@@ -20,9 +20,21 @@ const sessionStorageMap = new WeakMap<MockWindow, MockStorage>();
20
20
const eventClassMap = new WeakMap < MockWindow , any > ( ) ;
21
21
const customEventClassMap = new WeakMap < MockWindow , any > ( ) ;
22
22
const keyboardEventClassMap = new WeakMap < MockWindow , any > ( ) ;
23
-
23
+ const nativeClearInterval = clearInterval ;
24
+ const nativeClearTimeout = clearTimeout ;
25
+ const nativeSetInterval = setInterval ;
26
+ const nativeSetTimeout = setTimeout ;
27
+ const nativeURL = URL ;
24
28
25
29
export class MockWindow {
30
+ __clearInterval : typeof nativeClearInterval ;
31
+ __clearTimeout : typeof nativeClearTimeout ;
32
+ __setInterval : typeof nativeSetInterval ;
33
+ __setTimeout : typeof nativeSetTimeout ;
34
+ __maxTimeout : number ;
35
+ __allowInterval : boolean ;
36
+ URL : typeof URL ;
37
+
26
38
console : Console ;
27
39
customElements : CustomElementRegistry ;
28
40
document : Document ;
@@ -50,6 +62,7 @@ export class MockWindow {
50
62
this . performance = new MockPerformance ( ) ;
51
63
this . customElements = new MockCustomElementRegistry ( this as any ) ;
52
64
this . console = createConsole ( ) ;
65
+ resetWindowDefaults ( this ) ;
53
66
resetWindowDimensions ( this ) ;
54
67
}
55
68
@@ -337,19 +350,17 @@ export class MockWindow {
337
350
get window ( ) {
338
351
return this ;
339
352
}
340
-
341
- URL = URL ;
342
-
343
- // used so the native setTimeout can actually be used
344
- // but allows us to monkey patch the window.setTimeout
345
- __clearInterval = clearInterval ;
346
- __clearTimeout = clearTimeout ;
347
- __setInterval = setInterval ;
348
- __setTimeout = setTimeout ;
349
- __maxTimeout = 30000 ;
350
- __allowInterval = true ;
351
353
}
352
354
355
+ function resetWindowDefaults ( win : any ) {
356
+ win . __clearInterval = nativeClearInterval ;
357
+ win . __clearTimeout = nativeClearTimeout ;
358
+ win . __setInterval = nativeSetInterval ;
359
+ win . __setTimeout = nativeSetTimeout ;
360
+ win . __maxTimeout = 30000 ;
361
+ win . __allowInterval = true ;
362
+ win . URL = nativeURL ;
363
+ }
353
364
354
365
export function createWindow ( html : string | boolean = null ) : Window {
355
366
return new MockWindow ( html ) as any ;
@@ -403,7 +414,7 @@ export function resetWindow(win: Window) {
403
414
delete ( win as any ) [ key ] ;
404
415
}
405
416
}
406
-
417
+ resetWindowDefaults ( win ) ;
407
418
resetWindowDimensions ( win ) ;
408
419
409
420
resetEventListeners ( win ) ;
0 commit comments