diff --git a/test/cases/testUtils.ts b/test/cases/testUtils.ts index 3807dae..4b3f87a 100644 --- a/test/cases/testUtils.ts +++ b/test/cases/testUtils.ts @@ -12,7 +12,8 @@ describe("Test utils ", () => { }, { - } + }, + false ), "Did not match empty expect"); assert(partialDeepEquals( [{a: [1,2,3]}, {a: [1,2]}], @@ -39,7 +40,8 @@ describe("Test utils ", () => { { vip: false, old: 19 - } + }, + false ), "Matched different properties"); // do not match missing property assert(!partialDeepEquals( @@ -53,7 +55,8 @@ describe("Test utils ", () => { child: { name: "" } - } + }, + false )); assert(!partialDeepEquals( { @@ -69,7 +72,8 @@ describe("Test utils ", () => { child: { name: "" } - } + }, + false ), "Matched incorrect child property"); assert(!partialDeepEquals( { @@ -91,7 +95,8 @@ describe("Test utils ", () => { name: "b", } } - } + }, + false ), "Matched incorrected 2-nested property"); assert(partialDeepEquals( { diff --git a/test/utils.ts b/test/utils.ts index e70532f..3636151 100644 --- a/test/utils.ts +++ b/test/utils.ts @@ -1,4 +1,5 @@ import {config} from "../src/config"; +import { Logger } from "../src/utils/logger"; export function getbaseURL(): string { return `http://localhost:${config.port}`; @@ -13,14 +14,27 @@ export type Done = (err?: any) => void; * * Check object contains expected properties */ -export const partialDeepEquals = (actual: Record, expected: Record): boolean => { +export const partialDeepEquals = (actual: Record, expected: Record, print = true): boolean => { // loop over key, value of expected for (const [ key, value ] of Object.entries(expected)) { // if value is object or array, recurse if (Array.isArray(value) || typeof value === "object") { - if (!partialDeepEquals(actual?.[key], value)) return false; + if (!partialDeepEquals(actual?.[key], value, false)) { + if (print) printActualExpected(actual, expected); + + return false; + } + } + else if (actual?.[key] !== value) { + if (print) printActualExpected(actual, expected); + + return false; } - else if (actual?.[key] !== value) return false; } return true; }; + +function printActualExpected(actual: Record, expected: Record): void { + Logger.error(`Actual: ${JSON.stringify(actual)}`); + Logger.error(`Expected: ${JSON.stringify(expected)}`); +} \ No newline at end of file