-
Notifications
You must be signed in to change notification settings - Fork 0
/
setupTests.ts
51 lines (46 loc) · 1.18 KB
/
setupTests.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
// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import "@testing-library/jest-dom";
const noop = () => {};
Object.defineProperty(window, "scrollTo", { value: noop, writable: true });
const originalOffsetHeight = Object.getOwnPropertyDescriptor(
HTMLElement.prototype,
"offsetHeight",
)!;
const originalOffsetWidth = Object.getOwnPropertyDescriptor(
HTMLElement.prototype,
"offsetWidth",
)!;
beforeAll(() => {
Object.defineProperty(HTMLElement.prototype, "offsetHeight", {
configurable: true,
value: 50,
});
Object.defineProperty(HTMLElement.prototype, "offsetWidth", {
configurable: true,
value: 50,
});
});
afterAll(() => {
Object.defineProperty(
HTMLElement.prototype,
"offsetHeight",
originalOffsetHeight,
);
Object.defineProperty(
HTMLElement.prototype,
"offsetWidth",
originalOffsetWidth,
);
});
window.matchMedia =
window.matchMedia ||
function () {
return {
matches: false,
addListener: function () {},
removeListener: function () {},
};
};