fix(core): update
This commit is contained in:
@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartexpect',
|
||||
version: '1.0.18',
|
||||
version: '1.0.19',
|
||||
description: 'manage expectations in code'
|
||||
}
|
||||
|
@ -184,6 +184,26 @@ export class Assertion {
|
||||
});
|
||||
}
|
||||
|
||||
public toHaveDeepProperty(properties: string[]) {
|
||||
return this.runCheck(() => {
|
||||
let obj = this.getObjectToTestReference();
|
||||
let currentPath = '';
|
||||
|
||||
for (const property of properties) {
|
||||
if (currentPath) {
|
||||
currentPath += `.${property}`;
|
||||
} else {
|
||||
currentPath = property;
|
||||
}
|
||||
|
||||
if (!obj || !(property in obj)) {
|
||||
throw new Error(`Missing property at path "${currentPath}" in ${this.baseReference}`);
|
||||
}
|
||||
obj = obj[property];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public toBeGreaterThan(numberArg: number) {
|
||||
return this.runCheck(() => {
|
||||
const result = this.getObjectToTestReference() > numberArg;
|
||||
@ -240,6 +260,8 @@ export class Assertion {
|
||||
});
|
||||
}
|
||||
|
||||
// Array
|
||||
|
||||
public toContain(itemArg: any) {
|
||||
return this.runCheck(() => {
|
||||
const result =
|
||||
@ -253,6 +275,47 @@ export class Assertion {
|
||||
});
|
||||
}
|
||||
|
||||
public toBeEmptyArray() {
|
||||
return this.runCheck(() => {
|
||||
const arrayRef = this.getObjectToTestReference();
|
||||
if (!Array.isArray(arrayRef) || arrayRef.length !== 0) {
|
||||
throw new Error(`Expected ${this.baseReference} to be an empty array, but it was not.`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public toContainAll(values: any[]) {
|
||||
return this.runCheck(() => {
|
||||
const arrayRef = this.getObjectToTestReference();
|
||||
if (!Array.isArray(arrayRef)) {
|
||||
throw new Error(`Expected ${this.baseReference} to be an array.`);
|
||||
}
|
||||
|
||||
for (const value of values) {
|
||||
if (!arrayRef.includes(value)) {
|
||||
throw new Error(
|
||||
`Expected ${this.baseReference} to include value "${value}", but it did not.`
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public toExclude(value: any) {
|
||||
return this.runCheck(() => {
|
||||
const arrayRef = this.getObjectToTestReference();
|
||||
if (!Array.isArray(arrayRef)) {
|
||||
throw new Error(`Expected ${this.baseReference} to be an array.`);
|
||||
}
|
||||
|
||||
if (arrayRef.includes(value)) {
|
||||
throw new Error(
|
||||
`Expected ${this.baseReference} to exclude value "${value}", but it included it.`
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public toStartWith(itemArg: any) {
|
||||
return this.runCheck(() => {
|
||||
const testObject = this.getObjectToTestReference();
|
||||
@ -466,6 +529,14 @@ export class Assertion {
|
||||
});
|
||||
}
|
||||
|
||||
public customAssertion(assertionFunction: (value: any) => boolean, errorMessage: string) {
|
||||
return this.runCheck(() => {
|
||||
if (!assertionFunction(this.getObjectToTestReference())) {
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public property(propertyNameArg: string) {
|
||||
this.propertyDrillDown.push(propertyNameArg);
|
||||
return this;
|
||||
|
@ -1,5 +1,5 @@
|
||||
import * as smartdelay from '@pushrocks/smartdelay';
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
import * as smartdelay from '@push.rocks/smartdelay';
|
||||
import * as smartpromise from '@push.rocks/smartpromise';
|
||||
|
||||
export { smartdelay, smartpromise };
|
||||
|
||||
|
Reference in New Issue
Block a user