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
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions packages/jest-environment-jsdom/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ 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 {
function isWin(globals: Win): 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,6 +119,7 @@ class JSDOMEnvironment implements JestEnvironment {
}
}
this.errorEventListener = null;
// @ts-ignore
this.global = null;
lh0x00 marked this conversation as resolved.
Show resolved Hide resolved
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;
Expand Down