diff --git a/tests/javascripts/apiKey.test.js b/tests/javascripts/apiKey.test.js index 4d693691b..34f7509c8 100644 --- a/tests/javascripts/apiKey.test.js +++ b/tests/javascripts/apiKey.test.js @@ -54,6 +54,8 @@ describe('API key', () => { describe("If copy command is available", () => { + let componentHeightOnLoad; + beforeAll(() => { // assume copy command is available @@ -79,6 +81,10 @@ describe('API key', () => { component = document.querySelector('[data-module=api-key]'); + // mock DOM API called for element height + componentHeightOnLoad = 50; + jest.spyOn(component, 'offsetHeight', 'get').mockImplementation(() => componentHeightOnLoad); + // start the module window.GOVUK.modules.start(); @@ -111,6 +117,13 @@ describe('API key', () => { }); + test("It should set the component's minimum height based on its height when the page loads", () => { + + // to prevent the position of the button moving when the state changes + expect(window.getComputedStyle(component)['min-height']).toEqual(`${componentHeightOnLoad}px`); + + }); + }); describe("If you click the 'Copy API key to clipboard' button", () => {