-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathjest.setup.ts
More file actions
33 lines (30 loc) · 1016 Bytes
/
jest.setup.ts
File metadata and controls
33 lines (30 loc) · 1016 Bytes
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
import { TextDecoder, TextEncoder } from "util";
import { ReadableStream, TransformStream, WritableStream } from "stream/web";
import "whatwg-fetch";
// Polyfills required by MSW 2.x
global.TextEncoder = TextEncoder;
global.TextDecoder = TextDecoder as typeof global.TextDecoder;
global.ReadableStream = ReadableStream as typeof global.ReadableStream;
global.TransformStream = TransformStream as typeof global.TransformStream;
global.WritableStream = WritableStream as typeof global.WritableStream;
// BroadcastChannel polyfill for MSW
global.BroadcastChannel = class BroadcastChannel {
name: string;
constructor(name: string) {
this.name = name;
}
postMessage() {}
close() {}
addEventListener() {}
removeEventListener() {}
dispatchEvent() {
return true;
}
onmessage = null;
onmessageerror = null;
} as unknown as typeof global.BroadcastChannel;
global.ResizeObserver = jest.fn().mockImplementation(() => ({
observe: jest.fn(),
unobserve: jest.fn(),
disconnect: jest.fn()
}));