-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient-internals.test.ts
61 lines (54 loc) · 1.62 KB
/
client-internals.test.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
52
53
54
55
56
57
58
59
60
61
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable no-native-reassign */
import {
getAbortController,
getFetch,
} from '../../client/src/internals/fetchHelpers';
describe('getAbortController() from..', () => {
test('passed', () => {
const sym: any = Symbol('test');
expect(getAbortController(sym)).toBe(sym);
});
test('window', () => {
const sym: any = Symbol('test');
(global as any).AbortController = undefined;
(global as any).window = {};
(global as any).window = AbortController = sym;
expect(getAbortController()).toBe(sym);
});
test('global', () => {
const sym: any = Symbol('test');
(global as any).AbortController = sym;
delete (global as any).window;
expect(getAbortController()).toBe(sym);
});
test('neither', () => {
(global as any).AbortController = undefined;
(global as any).window = undefined;
expect(getAbortController()).toBe(null);
});
});
describe('getFetch() from...', () => {
test('passed', () => {
const sym: any = Symbol('test');
expect(getFetch(sym)).toBe(sym);
});
test('window', () => {
const sym: any = Symbol('test');
(global as any).fetch = undefined;
(global as any).window = {};
(global as any).window.fetch = sym;
expect(getFetch()).toBe(sym);
});
test('global', () => {
const sym: any = Symbol('test');
(global as any).fetch = sym;
delete (global as any).window;
expect(getFetch()).toBe(sym);
});
test('neither -> throws', () => {
(global as any).fetch = undefined;
(global as any).window = undefined;
expect(() => getFetch()).toThrowError();
});
});