mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-25 08:44:23 -04:00
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:
@@ -145,15 +145,22 @@ describe('FullscreenTable', () => {
|
|||||||
describe("the height of the table should fit the vertical space available to it", () => {
|
describe("the height of the table should fit the vertical space available to it", () => {
|
||||||
|
|
||||||
let containerBoundingClientRectSpy;
|
let containerBoundingClientRectSpy;
|
||||||
|
let containerClientRectsSpy;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
|
||||||
|
let clientRect = { top: 500 };
|
||||||
|
|
||||||
// set the height and offset of the window and table container from the top of the document
|
// 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
|
// so just the top 268px of it appears on-screen
|
||||||
windowMock.setHeightTo(768);
|
windowMock.setHeightTo(768);
|
||||||
container.setAttribute('style', 'height: 1000px');
|
container.setAttribute('style', 'height: 1000px');
|
||||||
|
|
||||||
containerBoundingClientRectSpy = jest.spyOn(container, 'getBoundingClientRect')
|
containerBoundingClientRectSpy = jest.spyOn(container, 'getBoundingClientRect')
|
||||||
containerBoundingClientRectSpy.mockImplementation(() => { return { top: 500 } });
|
containerBoundingClientRectSpy.mockImplementation(() => clientRect);
|
||||||
|
|
||||||
|
containerClientRectsSpy = jest.spyOn(container, 'getClientRects')
|
||||||
|
containerClientRectsSpy.mockImplementation(() => { return [clientRect] });
|
||||||
|
|
||||||
// start module
|
// start module
|
||||||
window.GOVUK.modules.start();
|
window.GOVUK.modules.start();
|
||||||
@@ -167,6 +174,7 @@ describe('FullscreenTable', () => {
|
|||||||
|
|
||||||
windowMock.reset();
|
windowMock.reset();
|
||||||
containerBoundingClientRectSpy.mockClear();
|
containerBoundingClientRectSpy.mockClear();
|
||||||
|
containerClientRectsSpy.mockClear();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user