901a9b17f57ca245cc0a10d90aef1d4f5b0d5f8e
[vid.git] / vid-webpack-master / cypress / support / steps / general / compareDeepObjects.step.ts
1 const { _ } = Cypress;
2
3 declare namespace Cypress {
4   interface Chainable {
5     deepCompare: typeof deepCompare,
6   }
7 }
8
9 function deepCompare(actual : any, expected : any) {
10   if(actual !== null && expected !== null){
11     let diff : any[] = [];
12     Cypress._.mergeWith(actual, expected, function (objectValue, sourceValue, key, object, source) {
13       if ( !(_.isEqual(objectValue, sourceValue)) && (Object(objectValue) !== objectValue)) {
14         diff.push("key: " +key + ", expected: " + sourceValue + ", actual: " + objectValue);
15       }
16     });
17
18     Cypress._.mergeWith(expected, actual, function (objectValue, sourceValue, key, object, source) {
19       if ( !(_.isEqual(objectValue, sourceValue)) && (Object(objectValue) !== objectValue)) {
20         diff.push("key: " +key + ", expected: " + sourceValue + ", actual: " + objectValue);
21       }
22     });
23
24     if(diff.length > 0){
25       console.error("diff", diff);
26       cy.log("The object are not equals", diff);
27       expect(actual).equals(expected, `diff: ${diff}, actual:${JSON.stringify(actual)}, expected:${JSON.stringify(expected)}`);
28     }
29   }
30 }
31
32 Cypress.Commands.add('deepCompare', deepCompare);