|
|
|
@ -373,41 +373,7 @@ export class Assertion {
|
|
|
|
|
|
|
|
|
|
public toMatchObject(objectArg: object) {
|
|
|
|
|
return this.runCheck(() => {
|
|
|
|
|
function deepEqual(obj1: any, obj2: any): boolean {
|
|
|
|
|
// If both are of primitive types and are equal
|
|
|
|
|
if (obj1 === obj2) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If either of them is null or not an object
|
|
|
|
|
if (typeof obj1 !== 'object' || obj1 === null || typeof obj2 !== 'object' || obj2 === null) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const keys1 = Object.keys(obj1);
|
|
|
|
|
const keys2 = Object.keys(obj2);
|
|
|
|
|
|
|
|
|
|
// If their properties' count doesn't match
|
|
|
|
|
if (keys1.length !== keys2.length) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Checking if every property in obj1 has a counterpart in obj2
|
|
|
|
|
for (const key of keys1) {
|
|
|
|
|
if (!keys2.includes(key)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!deepEqual(obj1[key], obj2[key])) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
const partialMatch = deepEqual(
|
|
|
|
|
this.getObjectToTestReference(),
|
|
|
|
|
objectArg
|
|
|
|
|
); // Note: Implement a deep comparison function or use one from a library
|
|
|
|
|
const partialMatch = plugins.fastDeepEqual(this.getObjectToTestReference(), objectArg); // Note: Implement a deep comparison function or use one from a library
|
|
|
|
|
if (!partialMatch) {
|
|
|
|
|
throw new Error(
|
|
|
|
|
`${this.baseReference} with drill down ${this.propertyDrillDown} does not match the object ${objectArg}`
|
|
|
|
@ -448,6 +414,28 @@ export class Assertion {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public toHaveLengthGreaterThan(length: number) {
|
|
|
|
|
return this.runCheck(() => {
|
|
|
|
|
const obj = this.getObjectToTestReference();
|
|
|
|
|
if (typeof obj.length !== 'number' || obj.length <= length) {
|
|
|
|
|
throw new Error(
|
|
|
|
|
`${this.baseReference} with drill down ${this.propertyDrillDown} does not have a length greater than ${length}`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public toHaveLengthLessThan(length: number) {
|
|
|
|
|
return this.runCheck(() => {
|
|
|
|
|
const obj = this.getObjectToTestReference();
|
|
|
|
|
if (typeof obj.length !== 'number' || obj.length >= length) {
|
|
|
|
|
throw new Error(
|
|
|
|
|
`${this.baseReference} with drill down ${this.propertyDrillDown} does not have a length less than ${length}`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public toBeDate() {
|
|
|
|
|
return this.runCheck(() => {
|
|
|
|
|
if (!(this.getObjectToTestReference() instanceof Date)) {
|
|
|
|
|