Skip to content

Commit

Permalink
fix: log JSDOM errors mor cleanly
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Feb 14, 2022
1 parent c961be9 commit 082f065
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/jest-environment-jsdom/src/index.ts
Original file line number Diff line number Diff line change
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 082f065

Please sign in to comment.