newspack-scripts 4.6.0-alpha.2 → 4.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/scripts/utils/jestSetup.js +32 -3
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@ import "@testing-library/jest-dom";
|
|
|
3
3
|
// matchMedia does not exist in JSDOM, see https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom
|
|
4
4
|
Object.defineProperty(window, "matchMedia", {
|
|
5
5
|
writable: true,
|
|
6
|
-
value: jest.fn().mockImplementation(query => ({
|
|
6
|
+
value: jest.fn().mockImplementation((query) => ({
|
|
7
7
|
matches: false,
|
|
8
8
|
media: query,
|
|
9
9
|
onchange: null,
|
|
@@ -11,6 +11,35 @@ Object.defineProperty(window, "matchMedia", {
|
|
|
11
11
|
removeListener: jest.fn(), // deprecated
|
|
12
12
|
addEventListener: jest.fn(),
|
|
13
13
|
removeEventListener: jest.fn(),
|
|
14
|
-
dispatchEvent: jest.fn()
|
|
15
|
-
}))
|
|
14
|
+
dispatchEvent: jest.fn(),
|
|
15
|
+
})),
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
// IntersectionObserver does not exist in JSDOM.
|
|
19
|
+
// https://stackoverflow.com/a/58651649/3772847
|
|
20
|
+
class MockIntersectionObserver {
|
|
21
|
+
constructor(fn) {
|
|
22
|
+
this.root = null;
|
|
23
|
+
this.rootMargin = "";
|
|
24
|
+
this.thresholds = [];
|
|
25
|
+
this.disconnect = () => null;
|
|
26
|
+
this.observe = () => null;
|
|
27
|
+
this.takeRecords = () => [];
|
|
28
|
+
this.unobserve = () => null;
|
|
29
|
+
|
|
30
|
+
// Pass a single entry, which is intersecting.
|
|
31
|
+
fn([{ isIntersecting: true }]);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
Object.defineProperty(window, "IntersectionObserver", {
|
|
36
|
+
writable: true,
|
|
37
|
+
configurable: true,
|
|
38
|
+
value: MockIntersectionObserver,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
Object.defineProperty(global, "IntersectionObserver", {
|
|
42
|
+
writable: true,
|
|
43
|
+
configurable: true,
|
|
44
|
+
value: MockIntersectionObserver,
|
|
16
45
|
});
|