-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbrowser-support.spec.ts
43 lines (33 loc) · 1.16 KB
/
browser-support.spec.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
import BrowserSupport from './browser-support';
describe('BrowserSupport', () => {
let link: HTMLLinkElement;
let support: BrowserSupport;
beforeEach(() => {
const createElement = document.createElement.bind(document);
link = {
relList: {
supports: jest.fn(() => true),
},
} as unknown as HTMLLinkElement;
jest.spyOn(document, 'createElement')
.mockImplementation(type => {
return type === 'link' ? link : createElement(type);
});
support = new BrowserSupport();
});
it('returns true if able to support rel type', () => {
expect(support.canSupportRel('preload'))
.toEqual(true);
});
it('returns false if unable to support rel type', () => {
jest.spyOn(link.relList, 'supports')
.mockReturnValue(false);
expect(support.canSupportRel('preload'))
.toEqual(false);
});
it('returns false if `relList` is not supported', () => {
link = {} as unknown as HTMLLinkElement;
expect(support.canSupportRel('preload'))
.toEqual(false);
});
});