@@ -20,9 +20,21 @@ const sessionStorageMap = new WeakMap<MockWindow, MockStorage>();
2020const eventClassMap = new WeakMap < MockWindow , any > ( ) ;
2121const customEventClassMap = new WeakMap < MockWindow , any > ( ) ;
2222const 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 ;
2428
2529export 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+
2638 console : Console ;
2739 customElements : CustomElementRegistry ;
2840 document : Document ;
@@ -50,6 +62,7 @@ export class MockWindow {
5062 this . performance = new MockPerformance ( ) ;
5163 this . customElements = new MockCustomElementRegistry ( this as any ) ;
5264 this . console = createConsole ( ) ;
65+ resetWindowDefaults ( this ) ;
5366 resetWindowDimensions ( this ) ;
5467 }
5568
@@ -337,19 +350,17 @@ export class MockWindow {
337350 get window ( ) {
338351 return this ;
339352 }
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 ;
351353}
352354
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+ }
353364
354365export function createWindow ( html : string | boolean = null ) : Window {
355366 return new MockWindow ( html ) as any ;
@@ -403,7 +414,7 @@ export function resetWindow(win: Window) {
403414 delete ( win as any ) [ key ] ;
404415 }
405416 }
406-
417+ resetWindowDefaults ( win ) ;
407418 resetWindowDimensions ( win ) ;
408419
409420 resetEventListeners ( win ) ;
0 commit comments