File tree Expand file tree Collapse file tree 1 file changed +15
-20
lines changed Expand file tree Collapse file tree 1 file changed +15
-20
lines changed Original file line number Diff line number Diff line change
1
+ import mock from 'xhr-mock' ;
2
+
3
+ const windowKeys = JSON . parse ( JSON . stringify ( Object . keys ( window ) ) ) ;
4
+
1
5
// Lifecycle Hooks
2
6
// -----------------------------------------------------------------------------
3
7
// Soft-reset jsdom. This clears the DOM and removes all attribute from the
@@ -13,30 +17,21 @@ beforeEach(async () => {
13
17
rootElm . removeChild ( rootElm . firstChild ) ;
14
18
}
15
19
16
- // Remove docsify side-effects
17
- [
18
- '__current_docsify_compiler__' ,
19
- '_paq' ,
20
- '$docsify' ,
21
- 'Docsify' ,
22
- 'DocsifyCompiler' ,
23
- 'ga' ,
24
- 'gaData' ,
25
- 'gaGlobal' ,
26
- 'gaplugins' ,
27
- 'gitter' ,
28
- 'google_tag_data' ,
29
- 'marked' ,
30
- 'Prism' ,
31
- ] . forEach ( prop => {
32
- if ( global [ prop ] ) {
33
- delete global [ prop ] ;
34
- }
35
- } ) ;
20
+ // Remove jest/docsify side-effects
21
+ Object . keys ( window )
22
+ . filter ( key => ! windowKeys . includes ( key ) )
23
+ . forEach ( key => {
24
+ delete window [ key ] ;
25
+ } ) ;
36
26
37
27
// Remove attributes
38
28
[ ...rootElm . attributes ] . forEach ( attr => rootElm . removeAttribute ( attr . name ) ) ;
39
29
40
30
// Restore base elements
41
31
rootElm . innerHTML = '<html><head></head><body></body></html>' ;
42
32
} ) ;
33
+
34
+ afterEach ( async ( ) => {
35
+ // Restore the global XMLHttpRequest object to its original state
36
+ mock . teardown ( ) ;
37
+ } ) ;
You can’t perform that action at this time.
0 commit comments