summaryrefslogtreecommitdiffhomepage
path: root/packages/browser/src/helpers/webAuthnAbortService.test.ts
diff options
context:
space:
mode:
authorMatthew Miller <matthew@millerti.me>2022-07-04 08:04:44 -0700
committerGitHub <noreply@github.com>2022-07-04 08:04:44 -0700
commit184cbb4457285817db4ded722d7b54528988e2e0 (patch)
tree3b895f8c273e924dd6fdd52c50fd2528575dc41d /packages/browser/src/helpers/webAuthnAbortService.test.ts
parent524e7f881624f36aa17f406bb25fa23d02449652 (diff)
parent5a5b5a3bdf7c709493fc9e63f0f02eed99f25baf (diff)
Merge pull request #214 from MasterKale/feat/conditional-ui
feat/conditional-ui
Diffstat (limited to 'packages/browser/src/helpers/webAuthnAbortService.test.ts')
-rw-r--r--packages/browser/src/helpers/webAuthnAbortService.test.ts42
1 files changed, 42 insertions, 0 deletions
diff --git a/packages/browser/src/helpers/webAuthnAbortService.test.ts b/packages/browser/src/helpers/webAuthnAbortService.test.ts
new file mode 100644
index 0000000..f4e6344
--- /dev/null
+++ b/packages/browser/src/helpers/webAuthnAbortService.test.ts
@@ -0,0 +1,42 @@
+import { webauthnAbortService } from './webAuthnAbortService';
+
+test('should create a new abort signal every time', () => {
+ const signal1 = webauthnAbortService.createNewAbortSignal();
+ const signal2 = webauthnAbortService.createNewAbortSignal();
+
+ expect(signal2).not.toBe(signal1);
+});
+
+test('should call abort() on existing controller when creating a new signal', () => {
+ // Populate `.controller`
+ webauthnAbortService.createNewAbortSignal();
+
+ // Spy on the existing instance of AbortController
+ const abortSpy = jest.fn();
+ // @ts-ignore
+ webauthnAbortService.controller?.abort = abortSpy;
+
+ // Generate a new signal, which should call `abort()` on the existing controller
+ webauthnAbortService.createNewAbortSignal();
+ expect(abortSpy).toHaveBeenCalledTimes(1);
+});
+
+test('should reset controller', () => {
+ // Reset the service
+ webauthnAbortService.reset();
+
+ // Populate `.controller`
+ webauthnAbortService.createNewAbortSignal();
+
+ // Spy on the existing instance of AbortController
+ const abortSpy = jest.fn();
+ // @ts-ignore
+ webauthnAbortService.controller?.abort = abortSpy;
+
+ // Reset the service
+ webauthnAbortService.reset();
+
+ // Generate a new signal, which should NOT call `abort()` because the controller was cleared
+ webauthnAbortService.createNewAbortSignal();
+ expect(abortSpy).toHaveBeenCalledTimes(0);
+});