blob: 57ce6473a5f14b27d5d7e1259e00d72926c13a6b (
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
35
|
import { browserSupportsWebAuthnAutofill } from './browserSupportsWebAuthnAutofill';
// Mock "isConditionalMediationAvailable"
const mockICMA = jest.fn();
beforeEach(() => {
mockICMA.mockReset();
// @ts-ignore 2741
window.PublicKeyCredential = jest.fn().mockReturnValue(() => {});
window.PublicKeyCredential.isConditionalMediationAvailable = mockICMA
.mockResolvedValue(true);
});
test('should return true when conditional mediation is supported', async () => {
const supportsAutofill = await browserSupportsWebAuthnAutofill();
expect(supportsAutofill).toEqual(true);
});
test('should return false when conditional mediation is not supported', async () => {
mockICMA.mockResolvedValue(false);
const supportsAutofill = await browserSupportsWebAuthnAutofill();
expect(supportsAutofill).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 supportsAutofill = await browserSupportsWebAuthnAutofill();
expect(supportsAutofill).toEqual(false);
});
|