From c074797a743c293c54aca6955af6b3f6d46b8a27 Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Mon, 7 Mar 2022 13:54:30 -0800 Subject: Define errors globally for testing --- .../browser/src/methods/startRegistration.test.ts | 53 ------------------- packages/browser/src/setupTests.ts | 61 ++++++++++++++++++++++ 2 files changed, 61 insertions(+), 53 deletions(-) (limited to 'packages/browser/src') diff --git a/packages/browser/src/methods/startRegistration.test.ts b/packages/browser/src/methods/startRegistration.test.ts index f875a08..683bae8 100644 --- a/packages/browser/src/methods/startRegistration.test.ts +++ b/packages/browser/src/methods/startRegistration.test.ts @@ -356,56 +356,3 @@ describe('WebAuthnError', () => { }); }); }); - -/** - * Custom errors raised by WebAuthn - */ - -class AbortError extends Error { - constructor() { - super(); - this.name = 'AbortError'; - } -} - -class ConstraintError extends Error { - constructor() { - super(); - this.name = 'ConstraintError'; - } -} - -class InvalidStateError extends Error { - constructor() { - super(); - this.name = 'InvalidStateError'; - } -} - -class NotAllowedError extends Error { - constructor() { - super(); - this.name = 'NotAllowedError'; - } -} - -class NotSupportedError extends Error { - constructor() { - super(); - this.name = 'NotSupportedError'; - } -} - -class SecurityError extends Error { - constructor() { - super(); - this.name = 'SecurityError'; - } -} - -class UnknownError extends Error { - constructor() { - super(); - this.name = 'UnknownError'; - } -} diff --git a/packages/browser/src/setupTests.ts b/packages/browser/src/setupTests.ts index 5b6efcf..fda8840 100644 --- a/packages/browser/src/setupTests.ts +++ b/packages/browser/src/setupTests.ts @@ -24,3 +24,64 @@ Object.defineProperty(window, 'location', { hostname: '', }, }); + +/** + * Define WebAuthn's custom API errors + */ + +class AbortError extends Error { + constructor() { + super(); + this.name = 'AbortError'; + } +} + +class ConstraintError extends Error { + constructor() { + super(); + this.name = 'ConstraintError'; + } +} + +class InvalidStateError extends Error { + constructor() { + super(); + this.name = 'InvalidStateError'; + } +} + +class NotAllowedError extends Error { + constructor() { + super(); + this.name = 'NotAllowedError'; + } +} + +class NotSupportedError extends Error { + constructor() { + super(); + this.name = 'NotSupportedError'; + } +} + +class SecurityError extends Error { + constructor() { + super(); + this.name = 'SecurityError'; + } +} + +class UnknownError extends Error { + constructor() { + super(); + this.name = 'UnknownError'; + } +} + +Object.defineProperty(global, 'AbortError', { value: AbortError }); +Object.defineProperty(global, 'ConstraintError', { value: ConstraintError }); +Object.defineProperty(global, 'InvalidStateError', { value: InvalidStateError }); +Object.defineProperty(global, 'NotAllowedError', { value: NotAllowedError }); +Object.defineProperty(global, 'NotSupportedError', { value: NotSupportedError }); +Object.defineProperty(global, 'SecurityError', { value: SecurityError }); +Object.defineProperty(global, 'UnknownError', { value: UnknownError }); -- cgit v1.2.3