-
Notifications
You must be signed in to change notification settings - Fork 167
Simplify spec DOM globals assignment #5622
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,7 +27,6 @@ export function createDOM() { | |
| : Promise.reject(new Error('Failed to load')); | ||
| } | ||
| })(), | ||
| runScripts: 'dangerously', | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed that |
||
| }); | ||
|
|
||
| // JSDOM doesn't implement `offsetParent`, which is used by some third-party libraries to detect | ||
|
|
@@ -61,6 +60,24 @@ export function createDOM() { | |
| .stub(dom.window, 'scrollTo') | ||
| .callsFake((scrollX, scrollY) => Object.assign(dom.window, { scrollX, scrollY })); | ||
|
|
||
| // If a script tag is added to the page, execute its callbacks as a successful or failed load, | ||
| // based on whether the `src` is `about:blank`. | ||
| new dom.window.MutationObserver((mutations) => { | ||
| mutations.forEach((mutation) => { | ||
| mutation.addedNodes.forEach((node) => { | ||
| if (node instanceof dom.window.HTMLScriptElement) { | ||
| if (node.src === 'about:blank') { | ||
| if (typeof node.onload === 'function') { | ||
| node.onload(); | ||
| } | ||
| } else if (typeof node.onerror === 'function') { | ||
| node.onerror(); | ||
| } | ||
| } | ||
| }); | ||
| }); | ||
| }).observe(dom.window.document.body, { childList: true, subtree: true }); | ||
|
|
||
| return dom; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this not work because
consoleis the real value and not the spy anymore?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.