From 5e0079f2304428a58cc2fc7118f329b40c403b52 Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Mon, 2 Oct 2023 23:01:42 -0700 Subject: Update tests --- .../src/methods/startAuthentication.test.ts | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'packages/browser/src/methods/startAuthentication.test.ts') diff --git a/packages/browser/src/methods/startAuthentication.test.ts b/packages/browser/src/methods/startAuthentication.test.ts index fb31dcc..3aaf33d 100644 --- a/packages/browser/src/methods/startAuthentication.test.ts +++ b/packages/browser/src/methods/startAuthentication.test.ts @@ -297,6 +297,22 @@ test('should set up autofill a.k.a. Conditional UI', async () => { .toEqual(0); }); +test('should set up conditional UI if "webauthn" is the only autocomplete token', async () => { + /** + * According to WHATWG "webauthn" can be the only token in the autocomplete attribute: + * https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill-detail-tokens + */ + document.body.innerHTML = ` +
+ + + +
+ `; + + await expect(startAuthentication(goodOpts1, true)).resolves; +}); + test('should throw error if autofill not supported', async () => { mockSupportsAutofill.mockResolvedValue(false); @@ -320,6 +336,25 @@ test('should throw error if no acceptable is found', async () => { rejected.toThrow(/no /i); }); +test('should throw error if "webauthn" is not final autocomplete token', async () => { + /** + * According to WHATWG "webauthn" must be the final token in the autocomplete attribute when + * multiple tokens are present: + * https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill-detail-tokens + */ + document.body.innerHTML = ` +
+ + + +
+ `; + + const rejected = await expect(startAuthentication(goodOpts1, true)).rejects; + rejected.toThrow(Error); + rejected.toThrow(/no /i); +}); + test('should return authenticatorAttachment if present', async () => { // Mock extension return values from authenticator mockNavigatorGet.mockImplementation((): Promise => { -- cgit v1.2.3