Skip to content

Commit

Permalink
Declare global prototype in JSDOMEnvironment to fix issue jestjs#8347
Browse files Browse the repository at this point in the history
  • Loading branch information
lh0x00 committed Apr 20, 2019
1 parent 31e06e8 commit 7003875
Showing 1 changed file with 8 additions and 7 deletions.
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 {
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;
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;
this.dom = null;
this.fakeTimers = null;
Expand Down

0 comments on commit 7003875

Please sign in to comment.