From 6be0f9680bcfa7ba542f1bb42a84e791e2c97a92 Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Wed, 2 Feb 2022 04:24:39 +0100 Subject: [PATCH] fix(core): update --- ts/smartexpect.classes.assertion.ts | 60 ++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 9 deletions(-) diff --git a/ts/smartexpect.classes.assertion.ts b/ts/smartexpect.classes.assertion.ts index d6adbb4..a18792b 100644 --- a/ts/smartexpect.classes.assertion.ts +++ b/ts/smartexpect.classes.assertion.ts @@ -29,7 +29,7 @@ export class Assertion { } else { let isOk = false; try { - runDirectOrNegated(checkFunction()) + runDirectOrNegated(checkFunction()); } catch (e) { isOk = true; } @@ -37,7 +37,7 @@ export class Assertion { throw new Error('Negated assertion is not ok!'); } } - } + }; if (this.executionMode === 'async') { const done = plugins.smartpromise.defer(); @@ -47,14 +47,14 @@ export class Assertion { if (this.timeoutSetting) { plugins.smartdelay.delayFor(this.timeoutSetting).then(() => { if (done.status === 'pending') { - done.reject(new Error(`${this.baseReference} timed out at ${this.timeoutSetting}!`)) - } + done.reject(new Error(`${this.baseReference} timed out at ${this.timeoutSetting}!`)); + } }); } - this.baseReference.then(promiseResultArg => { + this.baseReference.then((promiseResultArg) => { this.baseReference = promiseResultArg; done.resolve(runDirectOrNegated(checkFunction)); - }) + }); } return done.promise; } else { @@ -66,7 +66,8 @@ export class Assertion { return this.runCheck(() => { if (typeof this.baseReference !== 'string') { throw new Error( - `Assertion failed: ${this.baseReference} is not of type string, but typeof ${typeof this.baseReference}` + `Assertion failed: ${this.baseReference} is not of type string, but typeof ${typeof this + .baseReference}` ); } }); @@ -76,7 +77,8 @@ export class Assertion { return this.runCheck(() => { if (typeof this.baseReference !== 'number') { throw new Error( - `Assertion failed: ${this.baseReference} is not of type string, but typeof ${typeof this.baseReference}` + `Assertion failed: ${this.baseReference} is not of type string, but typeof ${typeof this + .baseReference}` ); } }); @@ -86,7 +88,8 @@ export class Assertion { return this.runCheck(() => { if (typeof this.baseReference !== 'boolean') { throw new Error( - `Assertion failed: ${this.baseReference} is not of type string, but typeof ${typeof this.baseReference}` + `Assertion failed: ${this.baseReference} is not of type string, but typeof ${typeof this + .baseReference}` ); } }); @@ -154,4 +157,43 @@ export class Assertion { } }); } + + public toBeNull() { + return this.runCheck(() => { + const result = this.baseReference === null; + if (!result) { + throw new Error(`${this.baseReference} is not null`); + } + }); + } + + public toBeUndefined() { + return this.runCheck(() => { + const result = this.baseReference === undefined; + if (!result) { + throw new Error(`${this.baseReference} is not undefined`); + } + }); + } + + public toBeNullOrUndefined() { + return this.runCheck(() => { + const result = this.baseReference === null || this.baseReference === undefined; + if (!result) { + throw new Error(`${this.baseReference} is not null or undefined`); + } + }); + } + + public toContain(itemArg: any) { + return this.runCheck(() => { + const result = this.baseReference instanceof Array && this.baseReference.find(itemArg2 => { + itemArg === itemArg2; + }) + if (!result) { + throw new Error(`${this.baseReference} is not contain ${itemArg}`); + } + }); + + } }