-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathjest.setup.js
More file actions
73 lines (67 loc) · 1.92 KB
/
jest.setup.js
File metadata and controls
73 lines (67 loc) · 1.92 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Add Jest-specific test setup
global.spyOn = (obj, method) => {
const spy = jest.spyOn(obj, method);
spy.calls = {
allArgs: () => spy.mock.calls,
all: () => spy.mock.calls.map(args => ({ args })),
count: () => spy.mock.calls.length,
first: () => spy.mock.calls[0],
mostRecent: () => spy.mock.calls[spy.mock.calls.length - 1]
};
return spy;
};
// Add TextEncoder/TextDecoder polyfills for JSDOM environment
if (typeof TextEncoder === 'undefined') {
const { TextEncoder, TextDecoder } = require('util');
global.TextEncoder = TextEncoder;
global.TextDecoder = TextDecoder;
}
// Ensure global references are properly set up for JSDOM
Object.defineProperty(global, 'Node', {
value: globalThis.Node || class Node { },
writable: true,
configurable: true
});
Object.defineProperty(global, 'HTMLElement', {
value: globalThis.HTMLElement || class HTMLElement { },
writable: true,
configurable: true
});
Object.defineProperty(global, 'SVGElement', {
value: globalThis.SVGElement || class SVGElement { },
writable: true,
configurable: true
});
// Mock jasmine functionality with Jest equivalents
global.jasmine = {
createSpy: (name) => {
const spy = jest.fn();
spy.calls = {
allArgs: () => spy.mock.calls,
all: () => spy.mock.calls.map(args => ({ args })),
count: () => spy.mock.calls.length,
first: () => spy.mock.calls[0],
mostRecent: () => spy.mock.calls[spy.mock.calls.length - 1]
};
spy.and = {
callThrough: () => spy,
returnValue: (val) => spy.mockReturnValue(val),
callFake: (fn) => spy.mockImplementation(fn)
};
return spy;
}
};
// Setup document if it doesn't exist (for JSDOM)
if (typeof document === 'undefined') {
global.document = {
createElement: () => ({
setAttribute: () => { },
style: {},
appendChild: () => { }
}),
createComment: () => ({}),
body: {
appendChild: () => { }
}
};
}