blob: dcd5c7c96cb1998bdcf5d761db9bbcf3b20f0968 (
plain)
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 { browserSupportsWebAuthn } from './browserSupportsWebAuthn';
beforeEach(() => {
// @ts-ignore 2741
window.PublicKeyCredential = jest.fn().mockReturnValue(() => {});
});
test('should return true when browser supports WebAuthn', () => {
expect(browserSupportsWebAuthn()).toBe(true);
});
test('should return false when browser does not support WebAuthn', () => {
// This looks weird but it appeases the linter so it's _fiiiine_
delete (window as { PublicKeyCredential: unknown }).PublicKeyCredential;
expect(browserSupportsWebAuthn()).toBe(false);
});
test('should return false when window is undefined', () => {
// Make window undefined as it is in node environments.
const windowSpy = jest.spyOn<typeof globalThis, 'window'>(
global,
'window',
'get',
);
// @ts-ignore: Intentionally making window unavailable
windowSpy.mockImplementation(() => undefined);
expect(window).toBe(undefined);
expect(browserSupportsWebAuthn()).toBe(false);
// Restore original window value.
windowSpy.mockRestore();
});
|