3 declare namespace Cypress {
5 deepCompare: typeof deepCompare,
9 function deepCompare(actual : any, expected : any) {
10 if(actual !== null && expected !== null){
11 const actualOriginal = JSON.stringify(actual);
12 const expectedOriginal = JSON.stringify(expected);
14 let diff : any[] = [];
15 Cypress._.mergeWith(actual, expected, function (objectValue, sourceValue, key, object, source) {
16 if ( !(_.isEqual(objectValue, sourceValue)) && (Object(objectValue) !== objectValue)) {
17 diff.push("key: " +key + ", expected: " + sourceValue + ", actual: " + objectValue);
21 Cypress._.mergeWith(expected, actual, function (objectValue, sourceValue, key, object, source) {
22 if ( !(_.isEqual(objectValue, sourceValue)) && (Object(objectValue) !== objectValue)) {
23 diff.push("key: " +key + ", expected: " + sourceValue + ", actual: " + objectValue);
28 console.error("diff", diff);
29 cy.log("The object are not equals", diff);
30 expect(actual).equals(expected, `diff: ${diff}, actual:${actualOriginal}, expected:${expectedOriginal}`);
35 Cypress.Commands.add('deepCompare', deepCompare);