-
Notifications
You must be signed in to change notification settings - Fork 791
/
patch.mjs
49 lines (40 loc) · 1.36 KB
/
patch.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Solves for situations where global code is mocked, like old Jest docs
// recommending to `null` out `window.CSS` for JSDOM's benefit
// https://github.com/thymikee/jest-preset-angular/commit/ac30648347ab41e0cbce741f66ae2a06b766fe13#diff-f2981abe444e6cc2b341b0d7cadb3932d2f1fbb6601aebeaf70f8bb387439d35
const originalWindowCSS = window.CSS;
function resetWindowCSSMock() {
Object.defineProperty(window, 'CSS', { value: originalWindowCSS });
}
function mockWindowCSS() {
Object.defineProperty(window, 'CSS', { value: null });
}
describe('patch', function () {
'use strict';
beforeEach(mockWindowCSS);
afterEach(resetWindowCSSMock);
it('can mock window.CSS to `null` on its own', function () {
assert.isNull(window.CSS);
});
it('resets css window mock', function () {
resetWindowCSSMock();
assert.equal(window.CSS, originalWindowCSS);
});
it('imports axe.js and works while patched and mocked', async function () {
assert.isNull(window.CSS);
try {
await import('/axe.js');
} catch (error) {
// Should not hit this assertion
assert.notOk(error);
}
});
it('imports axe.min.js and works while patched and mocked', async function () {
assert.isNull(window.CSS);
try {
await import('/axe.min.js');
} catch (error) {
// Should not hit this assertion
assert.notOk(error);
}
});
});