Conversation
**Why**: To avoid needing to cherry-pick individual window properties to promote to the global namespace, which often comes as a surprise, and likely won't be clear how to resolve when the need arises. Instead, assign all window properties as global properties, which is essentially how it behaves in a browser environment.
| : Promise.reject(new Error('Failed to load')); | ||
| } | ||
| })(), | ||
| runScripts: 'dangerously', |
There was a problem hiding this comment.
I noticed that Object.getOwnPropertyNames(window) would return a different result with this assigned, and was missing many properties (e.g. window.Element). After tracking down why we needed this in the first place, I came up with the substitute implementation below, which is also similar to what we do for images.
|
|
||
| const button = await findByText('doc_auth.buttons.upload_picture'); | ||
| expect(button.classList.contains('usa-button--outline')).to.be.true(); | ||
| expect(console).to.have.loggedError(/^Error: Could not load script:/); |
There was a problem hiding this comment.
does this not work because console is the real value and not the spy anymore?
There was a problem hiding this comment.
does this not work because
consoleis the real value and not the spy anymore?
Previously, we were letting JSDOM try to actually (virtually) load the script, and in this test scenario we were expecting that to fail, at which point JSDOM would log to the console, and we needed to allow for that to happen with loggedError.
Since we're no longer letting JSDOM load the scripts, the log no longer happens.
Why: To avoid needing to cherry-pick individual window properties to promote to the global namespace, which often comes as a surprise, and likely won't be clear how to resolve when the need arises. Instead, assign all window properties as global properties, which is essentially how it behaves in a browser environment.