From f52cb2a0a6753b96f7e188a4a355c7a5ab797fd4 Mon Sep 17 00:00:00 2001 From: Dave Honneffer Date: Sat, 18 Jun 2022 18:35:21 +0200 Subject: [PATCH] #509@patch: Fix GlobalRegistrator's unregister. --- packages/global-registrator/src/GlobalRegistrator.ts | 6 +++--- packages/global-registrator/test/react/React.test.tsx | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/global-registrator/src/GlobalRegistrator.ts b/packages/global-registrator/src/GlobalRegistrator.ts index 6cc615da5..c0854cf54 100644 --- a/packages/global-registrator/src/GlobalRegistrator.ts +++ b/packages/global-registrator/src/GlobalRegistrator.ts @@ -11,7 +11,7 @@ export default class GlobalRegistrator { */ public static register(): void { if (this.registered.length) { - throw new Error('Failed to registered. Happy DOM has already been globally registered.'); + throw new Error('Failed to register. Happy DOM has already been globally registered.'); } const window = new GlobalWindow(); for (const key of Object.keys(window)) { @@ -26,9 +26,9 @@ export default class GlobalRegistrator { * Registers Happy DOM globally. */ public static unregister(): void { - if (this.registered.length) { + if (!this.registered.length) { throw new Error( - 'Failed to unregistered. Happy DOM has not previously been globally registered.' + 'Failed to unregister. Happy DOM has not previously been globally registered.' ); } for (const key of this.registered) { diff --git a/packages/global-registrator/test/react/React.test.tsx b/packages/global-registrator/test/react/React.test.tsx index 0d371d53c..3130031c0 100644 --- a/packages/global-registrator/test/react/React.test.tsx +++ b/packages/global-registrator/test/react/React.test.tsx @@ -26,3 +26,5 @@ function unmountReactComponent(): void { mountReactComponent(); unmountReactComponent(); + +GlobalRegistrator.unregister();