summaryrefslogtreecommitdiffhomepage
path: root/packages/browser/src/methods
diff options
context:
space:
mode:
authorMatthew Miller <matthew@millerti.me>2022-06-20 11:44:44 -0700
committerMatthew Miller <matthew@millerti.me>2022-06-20 11:44:44 -0700
commit86196b555ae6d611dc53d2870a20c918a258c053 (patch)
tree006bc600da9e7129f5a2d1a9be2b2c4293d47e74 /packages/browser/src/methods
parent36905520b0d105eab4e8a32141134d189420666a (diff)
Update tests for abort support
Diffstat (limited to 'packages/browser/src/methods')
-rw-r--r--packages/browser/src/methods/startAuthentication.test.ts13
-rw-r--r--packages/browser/src/methods/startRegistration.test.ts13
2 files changed, 26 insertions, 0 deletions
diff --git a/packages/browser/src/methods/startAuthentication.test.ts b/packages/browser/src/methods/startAuthentication.test.ts
index f134dae..0ade8fa 100644
--- a/packages/browser/src/methods/startAuthentication.test.ts
+++ b/packages/browser/src/methods/startAuthentication.test.ts
@@ -10,6 +10,7 @@ import utf8StringToBuffer from '../helpers/utf8StringToBuffer';
import bufferToBase64URLString from '../helpers/bufferToBase64URLString';
import { WebAuthnError } from '../helpers/structs';
import { generateCustomError } from '../helpers/__jest__/generateCustomError';
+import { webauthnAbortService } from '../helpers/webAuthnAbortService';
import { startAuthentication } from './startAuthentication';
@@ -219,6 +220,18 @@ test('should support "cable" transport', async () => {
.toEqual("cable");
});
+test('should cancel an existing call when executed again', async () => {
+ const abortSpy = jest.spyOn(AbortController.prototype, 'abort');
+ // Reset the abort service so we get an accurate call count
+ // @ts-ignore
+ webauthnAbortService.controller = undefined;
+
+ // Fire off a request and immediately attempt a second one
+ startAuthentication(goodOpts1);
+ await startAuthentication(goodOpts1);
+ expect(abortSpy).toHaveBeenCalledTimes(1);
+});
+
describe('WebAuthnError', () => {
describe('AbortError', () => {
const AbortError = generateCustomError('AbortError');
diff --git a/packages/browser/src/methods/startRegistration.test.ts b/packages/browser/src/methods/startRegistration.test.ts
index 58d9acd..70eb975 100644
--- a/packages/browser/src/methods/startRegistration.test.ts
+++ b/packages/browser/src/methods/startRegistration.test.ts
@@ -8,6 +8,7 @@ import { generateCustomError } from '../helpers/__jest__/generateCustomError';
import { browserSupportsWebauthn } from '../helpers/browserSupportsWebauthn';
import bufferToBase64URLString from '../helpers/bufferToBase64URLString';
import { WebAuthnError } from '../helpers/structs';
+import { webauthnAbortService } from '../helpers/webAuthnAbortService';
import utf8StringToBuffer from '../helpers/utf8StringToBuffer';
@@ -211,6 +212,18 @@ test('should return "cable" transport from response', async () => {
expect(response.transports).toEqual(["cable"]);
});
+test('should cancel an existing call when executed again', async () => {
+ const abortSpy = jest.spyOn(AbortController.prototype, 'abort');
+ // Reset the abort service so we get an accurate call count
+ // @ts-ignore
+ webauthnAbortService.controller = undefined;
+
+ // Fire off a request and immediately attempt a second one
+ startRegistration(goodOpts1);
+ await startRegistration(goodOpts1);
+ expect(abortSpy).toHaveBeenCalledTimes(1);
+});
+
describe('WebAuthnError', () => {
describe('AbortError', () => {
const AbortError = generateCustomError('AbortError');