forked from forem/forem
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestSetup.js
More file actions
47 lines (41 loc) · 1.3 KB
/
testSetup.js
File metadata and controls
47 lines (41 loc) · 1.3 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
41
42
43
44
45
46
47
/* eslint-env jest, node */
import 'jest-axe/extend-expect';
import './app/assets/javascripts/lib/xss';
global.setImmediate = global.setTimeout;
global.ResizeObserver = class ResizeObserver {
disconnect() {}
observe() {}
unobserve() {}
};
// TODO: Remove this once https://github.com/nickcolley/jest-axe/issues/147 is fixed.
const { getComputedStyle } = window;
window.getComputedStyle = (elt) => getComputedStyle(elt);
process.on('unhandledRejection', (error) => {
// Errors thrown here are typically fetch responses that have not been mocked.
throw error;
});
expect.extend({
/**
* This matcher tests if its subject is neither null nor undefined.
*
* Jest's `toBeDefined` only tests if its subject is *strictly* not the value
* `undefined`, which makes it unsuitable for testing if a value exists as the
* value might be `null` (which would pass a `toBeDefined` check).
*
* @param {any} subject The subject of the matcher
* @returns
*/
toExist(subject) {
if (subject === null || subject === undefined) {
return {
pass: false,
message: () => `Expected ${this.utils.printReceived(subject)} to exist`,
};
}
return {
pass: true,
message: () =>
`Expected ${this.utils.printReceived(subject)} to not exist`,
};
},
});