diff --git a/packages/core/src/lib/Assertion.ts b/packages/core/src/lib/Assertion.ts index abb8837f..d3069d00 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 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. + * + * @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"] {