summaryrefslogtreecommitdiffhomepage
path: root/packages/browser/src/helpers/platformAuthenticatorIsAvailable.test.ts
blob: 3e0b65bc04f10da62bd76c95cb975ece038c5d2b (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 { 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 () => {
  delete (window as any).PublicKeyCredential;
  const isAvailable = await platformAuthenticatorIsAvailable();

  expect(isAvailable).toEqual(false);
});