Skip to content

Commit 65b439b

Browse files
authored
fix(custom-jsdom-html): fix style & babel config
1 parent ae8958b commit 65b439b

3 files changed

Lines changed: 34 additions & 19 deletions

File tree

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
test('jsdom custom html', async () => {
1+
test('jsdom custom html', () => {
2+
/* eslint-disable-next-line no-undef */
23
expect(document.getElementById('root')).toBeTruthy();
3-
});
4+
});
Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
module.exports = {
2-
preset: [['@babel/env', {
3-
targets: 'current'
4-
}]]
5-
}
2+
presets: [
3+
[
4+
'@babel/env',
5+
{
6+
targets: {
7+
node: 'current',
8+
},
9+
},
10+
],
11+
],
12+
};

packages/jest-environment-jsdom/src/index.ts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,26 @@ class JSDOMEnvironment implements JestEnvironment<number> {
3131
moduleMocker: ModuleMocker | null;
3232

3333
constructor(config: Config.ProjectConfig, options?: EnvironmentContext) {
34-
this.dom = new JSDOM(typeof config.testEnvironmentOptions.html === 'string' ? config.testEnvironmentOptions.html : '<!DOCTYPE html>', {
35-
pretendToBeVisual: true,
36-
resources:
37-
typeof config.testEnvironmentOptions.userAgent === 'string'
38-
? new ResourceLoader({
39-
userAgent: config.testEnvironmentOptions.userAgent,
40-
})
41-
: undefined,
42-
runScripts: 'dangerously',
43-
url: config.testURL,
44-
virtualConsole: new VirtualConsole().sendTo(options?.console || console),
45-
...config.testEnvironmentOptions,
46-
});
34+
this.dom = new JSDOM(
35+
typeof config.testEnvironmentOptions.html === 'string'
36+
? config.testEnvironmentOptions.html
37+
: '<!DOCTYPE html>',
38+
{
39+
pretendToBeVisual: true,
40+
resources:
41+
typeof config.testEnvironmentOptions.userAgent === 'string'
42+
? new ResourceLoader({
43+
userAgent: config.testEnvironmentOptions.userAgent,
44+
})
45+
: undefined,
46+
runScripts: 'dangerously',
47+
url: config.testURL,
48+
virtualConsole: new VirtualConsole().sendTo(
49+
options?.console || console,
50+
),
51+
...config.testEnvironmentOptions,
52+
},
53+
);
4754
const global = (this.global = this.dom.window.document
4855
.defaultView as unknown as Win);
4956

0 commit comments

Comments
 (0)