Skip to content

Commit

Permalink
fix: log JSDOM errors more cleanly
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Feb 14, 2022
1 parent c8a8456 commit b2e389b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -18,6 +18,7 @@
- `[expect]` Move typings of `.not`, `.rejects` and `.resolves` modifiers outside of `Matchers` interface ([#12346](https://github.com/facebook/jest/pull/12346))
- `[expect]` Expose `AsymmetricMatchers` and `RawMatcherFn` interfaces ([#12363](https://github.com/facebook/jest/pull/12363))
- `[jest-environment-jsdom]` Make `jsdom` accessible to extending environments again ([#12232](https://github.com/facebook/jest/pull/12232))
- `[jest-environment-jsdom]` Log JSDOM errors more cleanly ([#12386](https://github.com/facebook/jest/pull/12386))
- `[jest-config]` Correctly detect CI environment and update snapshots accordingly ([#12378](https://github.com/facebook/jest/pull/12378))
- `[jest-jasmine2, jest-types]` [**BREAKING**] Move all `jasmine` specific types from `@jest/types` to its own package ([#12125](https://github.com/facebook/jest/pull/12125))

Expand Down
11 changes: 8 additions & 3 deletions packages/jest-environment-jsdom/src/index.ts
Expand Up @@ -31,6 +31,13 @@ export default class JSDOMEnvironment implements JestEnvironment<number> {
moduleMocker: ModuleMocker | null;

constructor(config: Config.ProjectConfig, options?: EnvironmentContext) {
const anyConsole = options?.console ?? console;
const virtualConsole = new VirtualConsole();
virtualConsole.sendTo(anyConsole, {omitJSDOMErrors: true});
virtualConsole.on('jsdomError', error => {
anyConsole.error(error);
});

this.dom = new JSDOM(
typeof config.testEnvironmentOptions.html === 'string'
? config.testEnvironmentOptions.html
Expand All @@ -45,9 +52,7 @@ export default class JSDOMEnvironment implements JestEnvironment<number> {
: undefined,
runScripts: 'dangerously',
url: config.testURL,
virtualConsole: new VirtualConsole().sendTo(
options?.console || console,
),
virtualConsole,
...config.testEnvironmentOptions,
},
);
Expand Down

0 comments on commit b2e389b

Please sign in to comment.