blob: 6f2b91dd1a713c85995e92e07fc41d6e2e957b81 (
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
34
|
import { platformAuthenticatorIsAvailable } from './platformAuthenticatorIsAvailable';
const mockIsUVPAA = jest.fn();
beforeEach(() => {
mockIsUVPAA.mockReset();
// @ts-ignore 2741
window.PublicKeyCredential = jest.fn().mockReturnValue(() => {});
window.PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable = mockIsUVPAA
.mockResolvedValue(true);
});
test('should return true when platform authenticator is available', async () => {
const isAvailable = await platformAuthenticatorIsAvailable();
expect(isAvailable).toEqual(true);
});
test('should return false when platform authenticator is unavailable', async () => {
mockIsUVPAA.mockResolvedValue(false);
const isAvailable = await platformAuthenticatorIsAvailable();
expect(isAvailable).toEqual(false);
});
test('should return false when browser does not support WebAuthn', async () => {
// This looks weird but it appeases the linter so it's _fiiiine_
delete (window as { PublicKeyCredential: unknown }).PublicKeyCredential;
const isAvailable = await platformAuthenticatorIsAvailable();
expect(isAvailable).toEqual(false);
});
|