forked from JesperDramsch/python-deadlines
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.js
More file actions
80 lines (69 loc) · 1.95 KB
/
Copy pathsetup.js
File metadata and controls
80 lines (69 loc) · 1.95 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
74
75
76
77
78
79
80
/**
* Jest setup file - runs after test environment is set up
*/
// Add custom matchers from jest-dom
require('@testing-library/jest-dom');
// Set up global jQuery
global.$ = global.jQuery = require('../../static/js/jquery.min.js');
// Mock console methods to reduce noise in tests
global.console = {
...console,
error: jest.fn(console.error),
warn: jest.fn(console.warn),
log: jest.fn(console.log)
};
// Add custom matchers
expect.extend({
toBeWithinRange(received, floor, ceiling) {
const pass = received >= floor && received <= ceiling;
if (pass) {
return {
message: () => `expected ${received} not to be within range ${floor} - ${ceiling}`,
pass: true,
};
} else {
return {
message: () => `expected ${received} to be within range ${floor} - ${ceiling}`,
pass: false,
};
}
},
toHaveBeenCalledWithDate(received, expectedDate, tolerance = 1000) {
const calls = received.mock.calls;
const pass = calls.some(call => {
const arg = call[0];
if (arg instanceof Date || arg.cfp || arg.cfpExt) {
const date = new Date(arg.cfp || arg.cfpExt || arg);
return Math.abs(date - expectedDate) <= tolerance;
}
return false;
});
if (pass) {
return {
message: () => `expected not to be called with date near ${expectedDate}`,
pass: true,
};
} else {
return {
message: () => `expected to be called with date near ${expectedDate}`,
pass: false,
};
}
}
});
// Clean up after each test
afterEach(() => {
// Clear all timers
jest.clearAllTimers();
// Clear localStorage
localStorage.clear();
sessionStorage.clear();
// Clear all mocks
jest.clearAllMocks();
// Reset document body
document.body.innerHTML = '';
// Remove any event listeners
const oldElem = document.body;
const newElem = oldElem.cloneNode(true);
oldElem.parentNode.replaceChild(newElem, oldElem);
});