From e4b81f913c040b90d1749252ee83abc1f54f7251 Mon Sep 17 00:00:00 2001 From: Jose Luis Leon Date: Tue, 29 Aug 2023 12:56:11 -0500 Subject: [PATCH 1/2] feat(core): Add normalized() helper to Assertion base class --- packages/core/src/lib/Assertion.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/core/src/lib/Assertion.ts b/packages/core/src/lib/Assertion.ts index abb8837f..142a21a6 100644 --- a/packages/core/src/lib/Assertion.ts +++ b/packages/core/src/lib/Assertion.ts @@ -60,6 +60,19 @@ export class Assertion { this.not = new Proxy(this, { get: this.proxyInverter(true) }); } + /** + * A convenience method to normalized the assertion instance. If it was + * inverted with `.not`, it'll return it back to the previous non-inverted + * state. Otherwise, it returns the same instance. + * + * @returns the normalized assertion instance + */ + protected normalized(): this { + return this.inverted + ? new Proxy(this, { get: this.proxyInverter(false) }) + : this; + } + /** * A convenience method to execute the assertion. The inversion logic for * `.not` is already embedded in this method, so this should always be used @@ -79,9 +92,7 @@ export class Assertion { throw invertedError; } - return this.inverted - ? new Proxy(this, { get: this.proxyInverter(false) }) - : this; + return this.normalized(); } private proxyInverter(isInverted: boolean): ProxyHandler["get"] { From d8c81ef2800407698a6c8e27d2123e00d961115d Mon Sep 17 00:00:00 2001 From: Jose Luis Leon Date: Wed, 30 Aug 2023 09:47:51 -0500 Subject: [PATCH 2/2] Address @ChristianSama feedback --- packages/core/src/lib/Assertion.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/lib/Assertion.ts b/packages/core/src/lib/Assertion.ts index 142a21a6..d3069d00 100644 --- a/packages/core/src/lib/Assertion.ts +++ b/packages/core/src/lib/Assertion.ts @@ -61,7 +61,7 @@ export class Assertion { } /** - * A convenience method to normalized the assertion instance. If it was + * A convenience method to normalize the assertion instance. If it was * inverted with `.not`, it'll return it back to the previous non-inverted * state. Otherwise, it returns the same instance. *