-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathjest.setup.js
More file actions
40 lines (34 loc) · 1.18 KB
/
jest.setup.js
File metadata and controls
40 lines (34 loc) · 1.18 KB
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
import { setup } from '@sa11y/jest';
setup();
global.flushPromises = () => new Promise(resolve => setTimeout(resolve,0));
global.clearDOM = () => {
// When enabled, SA11Y handles cleaning up the DOM after asserting accessibility.
if(!process.env.SA11Y_CLEANUP) {
while (document.body.firstChild) {
document.body.removeChild(document.body.firstChild);
}
}
jest.clearAllMocks();
};
expect.extend({
toContainOptions(actual, expected) {
const valueExists = valueToCheck =>
[...actual].some(actualValue => {
return actualValue.value === valueToCheck;
});
const lengthCheck = actual.length === expected.length;
const pass =
lengthCheck &&
[...expected].every(expectedValue => {
return valueExists(expectedValue);
});
return {
message: () =>
`expected the picklist to contain options: ${JSON.stringify(expected)}
actual options: ${JSON.stringify(actual)}`,
pass,
};
}
});
const noop = () => {};
Object.defineProperty(window, 'scrollTo', { value: noop, writable: true });