Skip to content
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

Declare global prototype in JSDOMEnvironment to fix issue #8347 #8352

Merged
merged 4 commits into from Apr 21, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -17,6 +17,7 @@
- `[jest-core]` Make `detectOpenHandles` imply `runInBand` ([#8283](https://github.com/facebook/jest/pull/8283))
- `[jest-haste-map]` Fix the `mapper` option which was incorrectly ignored ([#8299](https://github.com/facebook/jest/pull/8299))
- `[jest-jasmine2]` Fix describe return value warning being shown if the describe function throws ([#8335](https://github.com/facebook/jest/pull/8335))
- `[jest-environment-jsdom]` Re-declare global prototype of JSDOMEnvironment ([#8352](https://github.com/facebook/jest/pull/8352))

### Chore & Maintenance

Expand Down
13 changes: 6 additions & 7 deletions packages/jest-environment-jsdom/src/index.ts
Expand Up @@ -15,11 +15,12 @@ import {JSDOM, VirtualConsole} from 'jsdom';

// The `Window` interface does not have an `Error.stackTraceLimit` property, but
// `JSDOMEnvironment` assumes it is there.
interface Win extends Window {
Error: {
stackTraceLimit: number;
type Win = Window &
Global.Global & {
Error: {
stackTraceLimit: number;
};
};
}

function isWin(globals: Win | Global.Global): globals is Win {
lh0x00 marked this conversation as resolved.
Show resolved Hide resolved
return (globals as Win).document !== undefined;
Expand All @@ -31,8 +32,7 @@ function isWin(globals: Win | Global.Global): globals is Win {
class JSDOMEnvironment implements JestEnvironment {
dom: JSDOM | null;
fakeTimers: FakeTimers<number> | null;
// @ts-ignore
global: Global.Global | Win | null;
global: Win;
jeysal marked this conversation as resolved.
Show resolved Hide resolved
errorEventListener: ((event: Event & {error: Error}) => void) | null;
moduleMocker: ModuleMocker | null;

Expand Down Expand Up @@ -119,7 +119,6 @@ class JSDOMEnvironment implements JestEnvironment {
}
}
this.errorEventListener = null;
this.global = null;
lh0x00 marked this conversation as resolved.
Show resolved Hide resolved
this.dom = null;
lh0x00 marked this conversation as resolved.
Show resolved Hide resolved
this.fakeTimers = null;
return Promise.resolve();
Expand Down