-
Notifications
You must be signed in to change notification settings - Fork 2
/
jest.setup.js
54 lines (48 loc) · 1.33 KB
/
jest.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
48
49
50
51
52
53
54
// Used for __tests__/testing-library.js
// Learn more: https://github.com/testing-library/jest-dom
import "@testing-library/jest-dom";
jest.mock("next/dynamic", () => () => {
const DynamicComponent = () => null;
DynamicComponent.displayName = "LoadableComponent";
DynamicComponent.preload = jest.fn();
return DynamicComponent;
});
jest.mock("next/router", () => require("next-router-mock"));
// Mock implementation of ResizeObserver
class ResizeObserver {
constructor(callback) {
this.callback = callback;
}
observe() {
// Optionally, you can implement mock behavior for observe if needed
}
unobserve() {
// Optionally, you can implement mock behavior for unobserve if needed
}
disconnect() {
// Optionally, you can implement mock behavior for disconnect if needed
}
}
// Assign the mock ResizeObserver to the global window object
global.ResizeObserver = ResizeObserver;
// Mock localStorage
const localStorageMock = (function () {
let store = {};
return {
getItem: function (key) {
return store[key] || null;
},
setItem: function (key, value) {
store[key] = value.toString();
},
clear: function () {
store = {};
},
removeItem: function (key) {
delete store[key];
},
};
})();
Object.defineProperty(window, "localStorage", {
value: localStorageMock,
});