summaryrefslogtreecommitdiffhomepage
path: root/packages/browser/src/helpers/browserSupportsWebauthn.test.ts
diff options
context:
space:
mode:
authorMatthew Miller <matthew@millerti.me>2021-08-23 20:18:27 -0700
committerMatthew Miller <matthew@millerti.me>2021-08-23 20:18:27 -0700
commit808256a244c6e21c2db6b29bfc0cfe24268b460c (patch)
tree849c619e3bc8e02884739a7c387e937b244fa0eb /packages/browser/src/helpers/browserSupportsWebauthn.test.ts
parent09c073098fc2ea506692de614d578c805b74705a (diff)
Rename supportsWebAuthn (and fix tests)
Diffstat (limited to 'packages/browser/src/helpers/browserSupportsWebauthn.test.ts')
-rw-r--r--packages/browser/src/helpers/browserSupportsWebauthn.test.ts27
1 files changed, 27 insertions, 0 deletions
diff --git a/packages/browser/src/helpers/browserSupportsWebauthn.test.ts b/packages/browser/src/helpers/browserSupportsWebauthn.test.ts
new file mode 100644
index 0000000..5308315
--- /dev/null
+++ b/packages/browser/src/helpers/browserSupportsWebauthn.test.ts
@@ -0,0 +1,27 @@
+import { browserSupportsWebauthn } from './browserSupportsWebauthn';
+
+beforeEach(() => {
+ // @ts-ignore 2741
+ window.PublicKeyCredential = jest.fn().mockReturnValue(() => {});
+});
+
+test('should return true when browser supports WebAuthn', () => {
+ expect(browserSupportsWebauthn()).toBe(true);
+});
+
+test('should return false when browser does not support WebAuthn', () => {
+ delete (window as any).PublicKeyCredential;
+ expect(browserSupportsWebauthn()).toBe(false);
+});
+
+test('should return false when window is undefined', () => {
+ // Make window undefined as it is in node environments.
+ const windowSpy = jest.spyOn<any, 'window'>(global, 'window', 'get');
+ windowSpy.mockImplementation(() => undefined);
+
+ expect(window).toBe(undefined);
+ expect(browserSupportsWebauthn()).toBe(false);
+
+ // Restore original window value.
+ windowSpy.mockRestore();
+});