summaryrefslogtreecommitdiffhomepage
path: root/packages/browser/src/helpers/supportsWebauthn.test.ts
blob: e11d77b9144f69b99b0b40c287b678f4958868a3 (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
import supportsWebauthn from './supportsWebauthn';

beforeEach(() => {
  // @ts-ignore 2741
  window.PublicKeyCredential = jest.fn().mockReturnValue(() => {});
});

test('should return true when browser supports WebAuthn', () => {
  expect(supportsWebauthn()).toBe(true);
});

test('should return false when browser does not support WebAuthn', () => {
  delete (window as any).PublicKeyCredential;
  expect(supportsWebauthn()).toBe(false);
});

test('should return false when window is undefined', () => {
  // Make window undefined as it is in node environments.
  const windowSpy = jest.spyOn<any, 'window'>(global, 'window', 'get');
  windowSpy.mockImplementation(() => undefined);

  expect(window).toBe(undefined);
  expect(supportsWebauthn()).toBe(false);

  // Restore original window value.
  windowSpy.mockRestore();
});