-
-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathvitest.setup.js
47 lines (41 loc) · 1.3 KB
/
vitest.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
38
39
40
41
42
43
44
45
46
47
import sinon from 'sinon';
import { expect, chai, describe } from 'vitest';
import sinonChai from 'sinon-chai';
chai.use(sinonChai);
globalThis.context = describe;
globalThis.sinon = sinon;
window.addEventListener('error', () => {})
// Something that's loaded before this file polyfills Symbol object.
// We need to verify that it works in IE without that.
if (/Trident/.test(window.navigator.userAgent)) {
window.Symbol = undefined;
}
// Fix Function#name on browsers that do not support it (IE).
// Taken from: https://stackoverflow.com/a/17056530/755391
if (!function f() {}.name) {
Object.defineProperty(Function.prototype, 'name', {
get() {
let name = (this.toString().match(/^function\s*([^\s(]+)/) || [])[1];
// For better performance only parse once, and then cache the
// result through a new accessor for repeated access.
Object.defineProperty(this, 'name', { value: name });
return name;
}
});
}
expect.extend({
equalNode: (obj, expected) => {
if (expected == null) {
return {
pass: obj == null,
message: () => `expected node to "== null" but got ${obj} instead.`
};
} else {
return {
pass: obj.tagName === expected.tagName && obj === expected,
message: () =>
`expected node to have tagName ${expected.tagName} but got ${obj.tagName} instead.`
};
}
}
});