From 98e48e68f9898e94c623f676295032e04bdc3d94 Mon Sep 17 00:00:00 2001 From: Tom Byers Date: Wed, 22 Jan 2020 10:13:37 +0000 Subject: [PATCH] Change the URL JSDOM uses for the current page https://jestjs.io/docs/en/configuration#testurl-string Affects all DOM APIs that return information about the URL, for example window.location. Why: We now have tests for setting/deleting cookies. Tough-cookie, the library JSDOM uses for cookie handling cookies doesn't allow setting cookies with `domain=localhost`. This is correct by RFC6265, the standard it follows, as domains must have 2 or more `.`s in them. The only way to set a cookie on `localhost` is to leave out the `domain` attribute. The code we are testing sets and deletes cookies set on specific domains so using `localhost` is out. We also cannot just set/delete cookies on the domains used as cookies are required to match the domain of the current page. The solution we are left with is to set the current page to one from production and make sure each cookie is set relative to that domain. Note: this introduces `testURL` in isolation to be sure it doesn't break any existing tests. --- tests/javascripts/jest.config.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/javascripts/jest.config.js b/tests/javascripts/jest.config.js index 9fde149df..adf68d50a 100644 --- a/tests/javascripts/jest.config.js +++ b/tests/javascripts/jest.config.js @@ -1,3 +1,4 @@ module.exports = { - setupFiles: ['./support/setup.js'] + setupFiles: ['./support/setup.js'], + testURL: 'https://www.notifications.service.gov.uk' }