diff --git a/tests/javascripts/authenticateSecurityKey.test.js b/tests/javascripts/authenticateSecurityKey.test.js index 110314325..8e4b04f4c 100644 --- a/tests/javascripts/authenticateSecurityKey.test.js +++ b/tests/javascripts/authenticateSecurityKey.test.js @@ -2,40 +2,39 @@ beforeAll(() => { window.CBOR = require('../../node_modules/cbor-js/cbor.js') require('../../app/assets/javascripts/authenticateSecurityKey.js') - // disable console.error() so we don't see it in test output - // you might need to comment this out to debug some failures - jest.spyOn(console, 'error').mockImplementation(() => { }) - - // ensure window.alert() is implemented to simplify errors - jest.spyOn(window, 'alert').mockImplementation(() => { }) + // populate missing values to allow consistent jest.spyOn() + window.fetch = () => { } + window.navigator.credentials = { get: () => { } } }) afterAll(() => { require('./support/teardown.js') + + // restore window attributes to their original undefined state + delete window.fetch + delete window.navigator.credentials }) describe('Authenticate with security key', () => { let button beforeEach(() => { + // disable console.error() so we don't see it in test output + // you might need to comment this out to debug some failures + jest.spyOn(console, 'error').mockImplementation(() => { }) + + // ensure window.alert() is implemented to simplify errors + jest.spyOn(window, 'alert').mockImplementation(() => { }) + document.body.innerHTML = ` - - ` + ` + button = document.querySelector('[data-module="authenticate-security-key"]') - - // populate missing values to allow consistent jest.spyOn() - window.fetch = () => { } - window.navigator.credentials = { get: () => { } } - window.alert = () => { } - window.GOVUK.modules.start() }) afterEach(() => { - // restore window attributes to their original undefined state - delete window.fetch - delete window.navigator.credentials - delete window.alert + jest.restoreAllMocks() }) test('authenticates a credential and redirects based on the admin app response', (done) => { diff --git a/tests/javascripts/registerSecurityKey.test.js b/tests/javascripts/registerSecurityKey.test.js index 14fea8487..043a84224 100644 --- a/tests/javascripts/registerSecurityKey.test.js +++ b/tests/javascripts/registerSecurityKey.test.js @@ -2,13 +2,6 @@ beforeAll(() => { window.CBOR = require('../../node_modules/cbor-js/cbor.js') require('../../app/assets/javascripts/registerSecurityKey.js') - // disable console.error() so we don't see it in test output - // you might need to comment this out to debug some failures - jest.spyOn(console, 'error').mockImplementation(() => {}) - - // ensure window.alert() is implemented to simplify errors - jest.spyOn(window, 'alert').mockImplementation(() => {}) - // populate missing values to allow consistent jest.spyOn() window.fetch = () => {} window.navigator.credentials = { create: () => {} } @@ -26,6 +19,13 @@ describe('Register security key', () => { let button beforeEach(() => { + // disable console.error() so we don't see it in test output + // you might need to comment this out to debug some failures + jest.spyOn(console, 'error').mockImplementation(() => {}) + + // ensure window.alert() is implemented to simplify errors + jest.spyOn(window, 'alert').mockImplementation(() => {}) + document.body.innerHTML = ` Register a key @@ -35,6 +35,10 @@ describe('Register security key', () => { window.GOVUK.modules.start() }) + afterEach(() => { + jest.restoreAllMocks() + }) + test('creates a new credential and reloads', (done) => { jest.spyOn(window, 'fetch').mockImplementationOnce((_url) => {