generated from League-of-Foundry-Developers/FoundryVTT-Module-Template
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathjest.setup.ts
52 lines (43 loc) · 1.02 KB
/
jest.setup.ts
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
50
51
52
import 'reflect-metadata';
import '@testing-library/jest-dom';
import { configure } from '@testing-library/svelte';
Object.defineProperty(global, 'Hooks', {
value: {
once: (_name: any, _cb: any) => {
return 0;
}
}
});
Object.defineProperty(global, 'foundry', {
value: {
utils: {
flattenObject: (obj: any, _d: number = 0) => {
return flattenObject(obj, _d);
}
}
}
});
import { TextEncoder, TextDecoder } from 'util';
Object.assign(global, { TextDecoder, TextEncoder });
function flattenObject(ob: any, _d: number = 0) {
var toReturn: any = {};
if (_d > 100) {
throw new Error('Maximum depth exceeded');
}
for (var i in ob) {
if (!ob.hasOwnProperty(i)) continue;
if (typeof ob[i] == 'object' && ob[i] !== null) {
var flatObject = flattenObject(ob[i], _d + 1);
for (var x in flatObject) {
if (!flatObject.hasOwnProperty(x)) continue;
toReturn[i + '.' + x] = flatObject[x];
}
} else {
toReturn[i] = ob[i];
}
}
return toReturn;
}
configure({
testIdAttribute: 'data-test'
});