From 56a2aab5f0d22095e84c8cc73a1f8278e4baec11 Mon Sep 17 00:00:00 2001 From: Tom Byers Date: Thu, 7 Nov 2019 15:31:38 +0000 Subject: [PATCH] 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`. --- tests/javascripts/fullscreenTable.test.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/javascripts/fullscreenTable.test.js b/tests/javascripts/fullscreenTable.test.js index 8917c0853..8bf1223b8 100644 --- a/tests/javascripts/fullscreenTable.test.js +++ b/tests/javascripts/fullscreenTable.test.js @@ -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(); });