1 | import AnimationFrame from './animation-frame';
|
2 | import RequestIdleCallback from './request-idle-callback';
|
3 | import Clock from './clock';
|
4 | import fetch from './fetch';
|
5 | import Location from './location';
|
6 | import MatchMedia from './match-media';
|
7 | import Storage from './storage';
|
8 | import Timer from './timer';
|
9 | import UserTiming from './user-timing';
|
10 | import IntersectionObserver from './intersection-observer';
|
11 | import Promise from './promise';
|
12 | import Dimension from './dimension';
|
13 | import {Connection} from './connection';
|
14 |
|
15 | export const connection = new Connection();
|
16 |
|
17 | export const animationFrame = new AnimationFrame();
|
18 | export const requestIdleCallback = new RequestIdleCallback();
|
19 |
|
20 | export const clock = new Clock();
|
21 |
|
22 | export {fetch};
|
23 |
|
24 | export const location = new Location();
|
25 |
|
26 | export const matchMedia = new MatchMedia();
|
27 | export {mediaQueryList} from './match-media';
|
28 |
|
29 | export const localStorage = new Storage();
|
30 | export const sessionStorage = new Storage();
|
31 |
|
32 | export const timer = new Timer();
|
33 | export const userTiming = new UserTiming();
|
34 | export const intersectionObserver = new IntersectionObserver();
|
35 | export const promise = new Promise();
|
36 |
|
37 | export const dimension = new Dimension();
|
38 |
|
39 | export function installMockStorage() {
|
40 | if (typeof window !== 'undefined') {
|
41 | Object.defineProperties(window, {
|
42 | localStorage: {
|
43 | value: localStorage,
|
44 | },
|
45 | sessionStorage: {
|
46 | value: sessionStorage,
|
47 | },
|
48 | });
|
49 | }
|
50 | }
|
51 |
|
52 | const mocksToEnsureReset = {
|
53 | clock,
|
54 | location,
|
55 | timer,
|
56 | promise,
|
57 | animationFrame,
|
58 | fetch,
|
59 | matchMedia,
|
60 | userTiming,
|
61 | intersectionObserver,
|
62 | connection,
|
63 | };
|
64 |
|
65 | export function ensureMocksReset() {
|
66 | for (const mockName of Object.keys(mocksToEnsureReset)) {
|
67 | if (mocksToEnsureReset[mockName].isMocked()) {
|
68 | throw new Error(
|
69 | `You did not reset the mocked ${mockName}. Make sure to call ${mockName}.restore() after your tests have run.`,
|
70 | );
|
71 | }
|
72 | }
|
73 |
|
74 | localStorage.restore();
|
75 | sessionStorage.restore();
|
76 | }
|