Skip to content

Commit 25084f8

Browse files
committed
Update jest/docsify side-effect cleanup
1 parent af7e713 commit 25084f8

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

test/config/jest.setup-tests.js

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import mock from 'xhr-mock';
2+
3+
const windowKeys = JSON.parse(JSON.stringify(Object.keys(window)));
4+
15
// Lifecycle Hooks
26
// -----------------------------------------------------------------------------
37
// Soft-reset jsdom. This clears the DOM and removes all attribute from the
@@ -13,30 +17,21 @@ beforeEach(async () => {
1317
rootElm.removeChild(rootElm.firstChild);
1418
}
1519

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+
});
3626

3727
// Remove attributes
3828
[...rootElm.attributes].forEach(attr => rootElm.removeAttribute(attr.name));
3929

4030
// Restore base elements
4131
rootElm.innerHTML = '<html><head></head><body></body></html>';
4232
});
33+
34+
afterEach(async () => {
35+
// Restore the global XMLHttpRequest object to its original state
36+
mock.teardown();
37+
});

0 commit comments

Comments
 (0)