Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
52b8a3f0d1 | |||
9213e7905f | |||
56fb434f7d | |||
b147de4713 | |||
6a43243a3b | |||
6be0f9680b |
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartexpect",
|
"name": "@pushrocks/smartexpect",
|
||||||
"version": "1.0.8",
|
"version": "1.0.11",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@pushrocks/smartexpect",
|
"name": "@pushrocks/smartexpect",
|
||||||
"version": "1.0.8",
|
"version": "1.0.11",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartdelay": "^2.0.13",
|
"@pushrocks/smartdelay": "^2.0.13",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartexpect",
|
"name": "@pushrocks/smartexpect",
|
||||||
"version": "1.0.8",
|
"version": "1.0.11",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "manage expectations in code",
|
"description": "manage expectations in code",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
|
@ -36,4 +36,12 @@ tap.test('should be greater than', async () => {
|
|||||||
smartexpect.expect(4).toBeLessThan(5);
|
smartexpect.expect(4).toBeLessThan(5);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
tap.test('should correctly determine toContain', async () => {
|
||||||
|
const hello = {
|
||||||
|
socool: 'yes'
|
||||||
|
};
|
||||||
|
const testArray = [hello];
|
||||||
|
smartexpect.expect(testArray).toContain(hello);
|
||||||
|
})
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
@ -29,7 +29,7 @@ export class Assertion {
|
|||||||
} else {
|
} else {
|
||||||
let isOk = false;
|
let isOk = false;
|
||||||
try {
|
try {
|
||||||
runDirectOrNegated(checkFunction())
|
runDirectOrNegated(checkFunction());
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
isOk = true;
|
isOk = true;
|
||||||
}
|
}
|
||||||
@ -37,7 +37,7 @@ export class Assertion {
|
|||||||
throw new Error('Negated assertion is not ok!');
|
throw new Error('Negated assertion is not ok!');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
if (this.executionMode === 'async') {
|
if (this.executionMode === 'async') {
|
||||||
const done = plugins.smartpromise.defer();
|
const done = plugins.smartpromise.defer();
|
||||||
@ -47,14 +47,14 @@ export class Assertion {
|
|||||||
if (this.timeoutSetting) {
|
if (this.timeoutSetting) {
|
||||||
plugins.smartdelay.delayFor(this.timeoutSetting).then(() => {
|
plugins.smartdelay.delayFor(this.timeoutSetting).then(() => {
|
||||||
if (done.status === 'pending') {
|
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;
|
this.baseReference = promiseResultArg;
|
||||||
done.resolve(runDirectOrNegated(checkFunction));
|
done.resolve(runDirectOrNegated(checkFunction));
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
return done.promise;
|
return done.promise;
|
||||||
} else {
|
} else {
|
||||||
@ -66,7 +66,8 @@ export class Assertion {
|
|||||||
return this.runCheck(() => {
|
return this.runCheck(() => {
|
||||||
if (typeof this.baseReference !== 'string') {
|
if (typeof this.baseReference !== 'string') {
|
||||||
throw new Error(
|
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(() => {
|
return this.runCheck(() => {
|
||||||
if (typeof this.baseReference !== 'number') {
|
if (typeof this.baseReference !== 'number') {
|
||||||
throw new Error(
|
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(() => {
|
return this.runCheck(() => {
|
||||||
if (typeof this.baseReference !== 'boolean') {
|
if (typeof this.baseReference !== 'boolean') {
|
||||||
throw new Error(
|
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,42 @@ 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.includes(itemArg);
|
||||||
|
if (!result) {
|
||||||
|
throw new Error(`${this.baseReference} is not contain ${itemArg}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user