-
Notifications
You must be signed in to change notification settings - Fork 361
/
jest.setup.js
37 lines (32 loc) · 1.08 KB
/
jest.setup.js
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
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,
};
}
});