Skip to content

Commit

Permalink
fix(custom-jsdom-html): fix style & babel config
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvelSQ authored Oct 12, 2021
1 parent ae8958b commit 65b439b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 19 deletions.
5 changes: 3 additions & 2 deletions e2e/custom-jsdom-html/__tests__/test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
test('jsdom custom html', async () => {
test('jsdom custom html', () => {
/* eslint-disable-next-line no-undef */
expect(document.getElementById('root')).toBeTruthy();
});
});
15 changes: 11 additions & 4 deletions e2e/custom-jsdom-html/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
module.exports = {
preset: [['@babel/env', {
targets: 'current'
}]]
}
presets: [
[
'@babel/env',
{
targets: {
node: 'current',
},
},
],
],
};
33 changes: 20 additions & 13 deletions packages/jest-environment-jsdom/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,26 @@ class JSDOMEnvironment implements JestEnvironment<number> {
moduleMocker: ModuleMocker | null;

constructor(config: Config.ProjectConfig, options?: EnvironmentContext) {
this.dom = new JSDOM(typeof config.testEnvironmentOptions.html === 'string' ? config.testEnvironmentOptions.html : '<!DOCTYPE html>', {
pretendToBeVisual: true,
resources:
typeof config.testEnvironmentOptions.userAgent === 'string'
? new ResourceLoader({
userAgent: config.testEnvironmentOptions.userAgent,
})
: undefined,
runScripts: 'dangerously',
url: config.testURL,
virtualConsole: new VirtualConsole().sendTo(options?.console || console),
...config.testEnvironmentOptions,
});
this.dom = new JSDOM(
typeof config.testEnvironmentOptions.html === 'string'
? config.testEnvironmentOptions.html
: '<!DOCTYPE html>',
{
pretendToBeVisual: true,
resources:
typeof config.testEnvironmentOptions.userAgent === 'string'
? new ResourceLoader({
userAgent: config.testEnvironmentOptions.userAgent,
})
: undefined,
runScripts: 'dangerously',
url: config.testURL,
virtualConsole: new VirtualConsole().sendTo(
options?.console || console,
),
...config.testEnvironmentOptions,
},
);
const global = (this.global = this.dom.window.document
.defaultView as unknown as Win);

Expand Down

0 comments on commit 65b439b

Please sign in to comment.