fix(core): update
This commit is contained in:
parent
52b8a3f0d1
commit
cdcf082ee0
@ -5,6 +5,7 @@ export type TExecutionType = 'sync' | 'async';
|
|||||||
export class Assertion {
|
export class Assertion {
|
||||||
executionMode: TExecutionType;
|
executionMode: TExecutionType;
|
||||||
baseReference: any;
|
baseReference: any;
|
||||||
|
propertyDrillDown: string[] = [];
|
||||||
private notSetting = false;
|
private notSetting = false;
|
||||||
private timeoutSetting = 0;
|
private timeoutSetting = 0;
|
||||||
constructor(baseReferenceArg: any, executionModeArg: TExecutionType) {
|
constructor(baseReferenceArg: any, executionModeArg: TExecutionType) {
|
||||||
@ -12,6 +13,14 @@ export class Assertion {
|
|||||||
this.executionMode = executionModeArg;
|
this.executionMode = executionModeArg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getObjectToTestReference() {
|
||||||
|
let returnObjectToTestReference = this.baseReference;
|
||||||
|
for (const property of this.propertyDrillDown) {
|
||||||
|
returnObjectToTestReference = returnObjectToTestReference[property];
|
||||||
|
}
|
||||||
|
return returnObjectToTestReference;
|
||||||
|
}
|
||||||
|
|
||||||
public get not() {
|
public get not() {
|
||||||
this.notSetting = true;
|
this.notSetting = true;
|
||||||
return this;
|
return this;
|
||||||
@ -64,9 +73,9 @@ export class Assertion {
|
|||||||
|
|
||||||
public toBeTypeofString() {
|
public toBeTypeofString() {
|
||||||
return this.runCheck(() => {
|
return this.runCheck(() => {
|
||||||
if (typeof this.baseReference !== 'string') {
|
if (typeof this.getObjectToTestReference() !== 'string') {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Assertion failed: ${this.baseReference} is not of type string, but typeof ${typeof this
|
`Assertion failed: ${this.baseReference} with drill down ${this.propertyDrillDown} is not of type string, but typeof ${typeof this
|
||||||
.baseReference}`
|
.baseReference}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -75,9 +84,9 @@ export class Assertion {
|
|||||||
|
|
||||||
public toBeTypeofNumber() {
|
public toBeTypeofNumber() {
|
||||||
return this.runCheck(() => {
|
return this.runCheck(() => {
|
||||||
if (typeof this.baseReference !== 'number') {
|
if (typeof this.getObjectToTestReference() !== 'number') {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Assertion failed: ${this.baseReference} is not of type string, but typeof ${typeof this
|
`Assertion failed: ${this.baseReference} with drill down ${this.propertyDrillDown} is not of type string, but typeof ${typeof this
|
||||||
.baseReference}`
|
.baseReference}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -86,9 +95,9 @@ export class Assertion {
|
|||||||
|
|
||||||
public toBeTypeofBoolean() {
|
public toBeTypeofBoolean() {
|
||||||
return this.runCheck(() => {
|
return this.runCheck(() => {
|
||||||
if (typeof this.baseReference !== 'boolean') {
|
if (typeof this.getObjectToTestReference() !== 'boolean') {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Assertion failed: ${this.baseReference} is not of type string, but typeof ${typeof this
|
`Assertion failed: ${this.baseReference} with drill down ${this.propertyDrillDown} is not of type string, but typeof ${typeof this
|
||||||
.baseReference}`
|
.baseReference}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -97,90 +106,90 @@ export class Assertion {
|
|||||||
|
|
||||||
public toEqual(comparisonObject: any) {
|
public toEqual(comparisonObject: any) {
|
||||||
return this.runCheck(() => {
|
return this.runCheck(() => {
|
||||||
const result = plugins.fastDeepEqual(this.baseReference, comparisonObject);
|
const result = plugins.fastDeepEqual(this.getObjectToTestReference(), comparisonObject);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
throw new Error(`${this.baseReference} does not equal ${comparisonObject}`);
|
throw new Error(`${this.baseReference} with drill down ${this.propertyDrillDown} does not equal ${comparisonObject}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public toBeTrue() {
|
public toBeTrue() {
|
||||||
return this.runCheck(() => {
|
return this.runCheck(() => {
|
||||||
const result = typeof this.baseReference === 'boolean' && this.baseReference === true;
|
const result = typeof this.getObjectToTestReference() === 'boolean' && this.getObjectToTestReference() === true;
|
||||||
if (!result) {
|
if (!result) {
|
||||||
throw new Error(`${this.baseReference} is not true or not of type boolean`);
|
throw new Error(`${this.baseReference} with drill down ${this.propertyDrillDown} is not true or not of type boolean`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public toBeFalse() {
|
public toBeFalse() {
|
||||||
return this.runCheck(() => {
|
return this.runCheck(() => {
|
||||||
const result = typeof this.baseReference === 'boolean' && this.baseReference === false;
|
const result = typeof this.getObjectToTestReference() === 'boolean' && this.getObjectToTestReference() === false;
|
||||||
if (!result) {
|
if (!result) {
|
||||||
throw new Error(`${this.baseReference} is not false or not of type boolean`);
|
throw new Error(`${this.baseReference} with drill down ${this.propertyDrillDown} is not false or not of type boolean`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public toBeInstanceOf(classArg: any) {
|
public toBeInstanceOf(classArg: any) {
|
||||||
return this.runCheck(() => {
|
return this.runCheck(() => {
|
||||||
const result = this.baseReference instanceof classArg;
|
const result = this.getObjectToTestReference() instanceof classArg;
|
||||||
if (!result) {
|
if (!result) {
|
||||||
throw new Error(`${this.baseReference} is not an instance of ${classArg}`);
|
throw new Error(`${this.baseReference} with drill down ${this.propertyDrillDown} is not an instance of ${classArg}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public toHaveProperty(propertyArg: string) {
|
public toHaveProperty(propertyArg: string) {
|
||||||
return this.runCheck(() => {
|
return this.runCheck(() => {
|
||||||
const result = !!this.baseReference[propertyArg];
|
const result = !!this.getObjectToTestReference()[propertyArg];
|
||||||
if (!result) {
|
if (!result) {
|
||||||
throw new Error(`${this.baseReference} does not have property ${propertyArg}`);
|
throw new Error(`${this.baseReference} with drill down ${this.propertyDrillDown} does not have property ${propertyArg}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public toBeGreaterThan(numberArg: number) {
|
public toBeGreaterThan(numberArg: number) {
|
||||||
return this.runCheck(() => {
|
return this.runCheck(() => {
|
||||||
const result = this.baseReference > numberArg;
|
const result = this.getObjectToTestReference() > numberArg;
|
||||||
if (!result) {
|
if (!result) {
|
||||||
throw new Error(`${this.baseReference} is not greater than ${numberArg}`);
|
throw new Error(`${this.baseReference} with drill down ${this.propertyDrillDown} is not greater than ${numberArg}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public toBeLessThan(numberArg: number) {
|
public toBeLessThan(numberArg: number) {
|
||||||
return this.runCheck(() => {
|
return this.runCheck(() => {
|
||||||
const result = this.baseReference < numberArg;
|
const result = this.getObjectToTestReference() < numberArg;
|
||||||
if (!result) {
|
if (!result) {
|
||||||
throw new Error(`${this.baseReference} is not less than ${numberArg}`);
|
throw new Error(`${this.baseReference} with drill down ${this.propertyDrillDown} is not less than ${numberArg}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public toBeNull() {
|
public toBeNull() {
|
||||||
return this.runCheck(() => {
|
return this.runCheck(() => {
|
||||||
const result = this.baseReference === null;
|
const result = this.getObjectToTestReference() === null;
|
||||||
if (!result) {
|
if (!result) {
|
||||||
throw new Error(`${this.baseReference} is not null`);
|
throw new Error(`${this.baseReference} with drill down ${this.propertyDrillDown} is not null`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public toBeUndefined() {
|
public toBeUndefined() {
|
||||||
return this.runCheck(() => {
|
return this.runCheck(() => {
|
||||||
const result = this.baseReference === undefined;
|
const result = this.getObjectToTestReference() === undefined;
|
||||||
if (!result) {
|
if (!result) {
|
||||||
throw new Error(`${this.baseReference} is not undefined`);
|
throw new Error(`${this.baseReference} with drill down ${this.propertyDrillDown} is not undefined`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public toBeNullOrUndefined() {
|
public toBeNullOrUndefined() {
|
||||||
return this.runCheck(() => {
|
return this.runCheck(() => {
|
||||||
const result = this.baseReference === null || this.baseReference === undefined;
|
const result = this.getObjectToTestReference() === null || this.getObjectToTestReference() === undefined;
|
||||||
if (!result) {
|
if (!result) {
|
||||||
throw new Error(`${this.baseReference} is not null or undefined`);
|
throw new Error(`${this.baseReference} with drill down ${this.propertyDrillDown} is not null or undefined`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -188,11 +197,16 @@ export class Assertion {
|
|||||||
public toContain(itemArg: any) {
|
public toContain(itemArg: any) {
|
||||||
return this.runCheck(() => {
|
return this.runCheck(() => {
|
||||||
const result =
|
const result =
|
||||||
this.baseReference instanceof Array &&
|
this.getObjectToTestReference() instanceof Array &&
|
||||||
this.baseReference.includes(itemArg);
|
this.getObjectToTestReference().includes(itemArg);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
throw new Error(`${this.baseReference} is not contain ${itemArg}`);
|
throw new Error(`${this.baseReference} with drill down ${this.propertyDrillDown} is not contain ${itemArg}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public property(propertyNameArg: string) {
|
||||||
|
this.propertyDrillDown.push(propertyNameArg);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user