diff options
author | Matthew Miller <matthew@millerti.me> | 2024-04-12 14:07:38 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-12 14:07:38 -0700 |
commit | 9340662a8400cadcb73c5f0c5fbb7aa5e4a635c1 (patch) | |
tree | 22fdfe6de58508c8351ea80901c33b95f970fa36 /packages/browser/src/helpers/browserSupportsWebAuthnAutofill.test.ts | |
parent | 59fde2895d337d46e0b0d978913015a01ed7975b (diff) | |
parent | fe3bf5a9954718b1abe921f79118ac2de32c96dd (diff) |
Merge pull request #557 from MasterKale/fix/544-ensure-webauthn-available-autofill-feature-check
fix/544-ensure-webauthn-available-autofill-feature-check
Diffstat (limited to 'packages/browser/src/helpers/browserSupportsWebAuthnAutofill.test.ts')
-rw-r--r-- | packages/browser/src/helpers/browserSupportsWebAuthnAutofill.test.ts | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/packages/browser/src/helpers/browserSupportsWebAuthnAutofill.test.ts b/packages/browser/src/helpers/browserSupportsWebAuthnAutofill.test.ts new file mode 100644 index 0000000..57ce647 --- /dev/null +++ b/packages/browser/src/helpers/browserSupportsWebAuthnAutofill.test.ts @@ -0,0 +1,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); +}); |