-
-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathjest.setup.js
More file actions
66 lines (53 loc) · 1.58 KB
/
Copy pathjest.setup.js
File metadata and controls
66 lines (53 loc) · 1.58 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
/* global jest */
// Add any global setup for Jest tests here
import 'core-js/stable';
// Setup Intl polyfill
global.IntlPolyfill = require('intl');
require('intl/locale-data/jsonp/en.js');
require('intl-pluralrules');
// Setup Jest DOM matchers
require('@testing-library/jest-dom');
global.chai = require('chai');
global.sinon = require('sinon');
global.before = beforeAll;
global.after = afterAll;
global.context = describe;
// Define global variables that might be expected in tests
global.__DEV__ = false;
global.__TEST__ = true;
global.__PROD__ = false;
global.__I18N_ENABLED__ = 'false';
global.__DEV_TOOLS__ = false;
window.config = {
API_HOST: 'http://app.tidepool.test', // For MSW testing
};
if (!global.URL) {
global.URL = require('url').URL;
}
if (!global.URL.createObjectURL) {
global.URL.createObjectURL = () => 'blob:test-url';
}
if (!console.save) {
console.save = () => {};
}
if (!global.Worker) {
global.Worker = class Worker {
constructor() {}
postMessage() {}
terminate() {}
addEventListener() {}
removeEventListener() {}
};
}
// Prevent computing of styles for faster test execution
// https://web.archive.org/web/20250216081109/https://www.helpscout.com/blog/improve-react-testing-times/
window.getComputedStyle = () => ({ getPropertyValue: () => undefined });
// Polyfill crypto.randomUUID for jsdom (not available in Node's test environment by default)
if (!global.crypto) global.crypto = {};
if (!global.crypto.randomUUID) {
let counter = 0;
global.crypto.randomUUID = () => `test-uuid-${++counter}`;
}
if (!window.scrollTo) {
window.scrollTo = () => {};
}