Mock out getClientRects for tests that need it

jQuery 3 calls `getClientRects` in the
`.innerHeight` code. Version 1 didn't.

This mocks out those calls to the same as
`getCoundingClientRect`.
This commit is contained in:
Tom Byers
2019-11-07 15:31:38 +00:00
parent f2b7c42f53
commit 56a2aab5f0

View File

@@ -145,15 +145,22 @@ describe('FullscreenTable', () => {
describe("the height of the table should fit the vertical space available to it", () => {
let containerBoundingClientRectSpy;
let containerClientRectsSpy;
beforeEach(() => {
let clientRect = { top: 500 };
// set the height and offset of the window and table container from the top of the document
// so just the top 268px of it appears on-screen
windowMock.setHeightTo(768);
container.setAttribute('style', 'height: 1000px');
containerBoundingClientRectSpy = jest.spyOn(container, 'getBoundingClientRect')
containerBoundingClientRectSpy.mockImplementation(() => { return { top: 500 } });
containerBoundingClientRectSpy.mockImplementation(() => clientRect);
containerClientRectsSpy = jest.spyOn(container, 'getClientRects')
containerClientRectsSpy.mockImplementation(() => { return [clientRect] });
// start module
window.GOVUK.modules.start();
@@ -167,6 +174,7 @@ describe('FullscreenTable', () => {
windowMock.reset();
containerBoundingClientRectSpy.mockClear();
containerClientRectsSpy.mockClear();
});