From 37ae04f67eac2b27587b832a357cea4936621dab Mon Sep 17 00:00:00 2001 From: Tom Byers Date: Tue, 21 Sep 2021 20:18:24 +0100 Subject: [PATCH] Make test comments explain use of require better Based on comments on the pull request associated with this work: https://github.com/alphagov/notifications-admin/pull/4023#discussion_r711156154 --- tests/javascripts/updateContent.test.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/javascripts/updateContent.test.js b/tests/javascripts/updateContent.test.js index 0214b64b1..c1496b4b7 100644 --- a/tests/javascripts/updateContent.test.js +++ b/tests/javascripts/updateContent.test.js @@ -31,10 +31,12 @@ beforeAll(() => { $.ajax.mockImplementation(() => jqueryAJAXReturnObj); - // because we're running in node, we can't execute the normal domdiff code like a browser because - // its variables (actually only one: domdiff) stay local to it - // in the normal browser environment it will attach to window so we replicate that here by using - // the CommonJS module version and assigning it to window + // using require to execute the version we use in our our frontend build here can't add + // the domdiff variable to this scope like it does when executed in browsers because + // that version doesn't export it + // we use CommonJS version instead because it does (as the default property) + // see https://nodejs.org/en/knowledge/getting-started/what-is-require/ for more info + // also, we're not a browser so we need to manually attach domdiff to window window.domdiff = require('domdiff/cjs').default; require('../../app/assets/javascripts/updateContent.js');