Skip to content

Commit a30ae44

Browse files
authored
feat(core): Add normalized() helper to Assertion base class (#106)
1 parent 01e0aeb commit a30ae44

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

packages/core/src/lib/Assertion.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,19 @@ export class Assertion<T> {
6060
this.not = new Proxy(this, { get: this.proxyInverter(true) });
6161
}
6262

63+
/**
64+
* A convenience method to normalize the assertion instance. If it was
65+
* inverted with `.not`, it'll return it back to the previous non-inverted
66+
* state. Otherwise, it returns the same instance.
67+
*
68+
* @returns the normalized assertion instance
69+
*/
70+
protected normalized(): this {
71+
return this.inverted
72+
? new Proxy(this, { get: this.proxyInverter(false) })
73+
: this;
74+
}
75+
6376
/**
6477
* A convenience method to execute the assertion. The inversion logic for
6578
* `.not` is already embedded in this method, so this should always be used
@@ -79,9 +92,7 @@ export class Assertion<T> {
7992
throw invertedError;
8093
}
8194

82-
return this.inverted
83-
? new Proxy(this, { get: this.proxyInverter(false) })
84-
: this;
95+
return this.normalized();
8596
}
8697

8798
private proxyInverter(isInverted: boolean): ProxyHandler<this>["get"] {

0 commit comments

Comments
 (0)