summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--packages/browser/src/helpers/supportsWebauthn.test.ts15
-rw-r--r--packages/browser/src/setupTests.ts4
2 files changed, 18 insertions, 1 deletions
diff --git a/packages/browser/src/helpers/supportsWebauthn.test.ts b/packages/browser/src/helpers/supportsWebauthn.test.ts
index 078c27d..f6b8a8e 100644
--- a/packages/browser/src/helpers/supportsWebauthn.test.ts
+++ b/packages/browser/src/helpers/supportsWebauthn.test.ts
@@ -1,4 +1,4 @@
-import supportsWebauthn from './supportsWebauthn';
+import supportsWebauthn from './supportsWebauthn'
beforeEach(() => {
// @ts-ignore 2741
@@ -13,3 +13,16 @@ test('should return false when browser does not support WebAuthn', () => {
delete window.PublicKeyCredential;
expect(supportsWebauthn()).toBe(false);
});
+
+test('should return false when window is undefined', () => {
+ // Make window undefined as it is in node environments.
+ // @ts-expect-error
+ const windowSpy = jest.spyOn(global, "window", "get");
+ windowSpy.mockImplementation(() => undefined);
+
+ expect(window).toBe(undefined)
+ expect(supportsWebauthn()).toBe(false);
+
+ // Restore original window value.
+ windowSpy.mockRestore()
+})
diff --git a/packages/browser/src/setupTests.ts b/packages/browser/src/setupTests.ts
index 019ba42..75833a8 100644
--- a/packages/browser/src/setupTests.ts
+++ b/packages/browser/src/setupTests.ts
@@ -3,6 +3,9 @@
// jest.spyOn(console, 'debug').mockImplementation();
// jest.spyOn(console, 'error').mockImplementation();
+// @ts-expect-error
+if (global.window) {
+
/**
* JSDom doesn't seem to support `credentials`, so let's define them here so we can mock their
* implementations in specific tests.
@@ -14,3 +17,4 @@ window.navigator.credentials = {
// assertion
get: jest.fn(),
};
+} \ No newline at end of file