From e13d886565890e3720c3321f5a44b0d352db6bab Mon Sep 17 00:00:00 2001 From: webbrain-one <295484252+webbrain-one@users.noreply.github.com> Date: Wed, 19 Aug 2026 13:47:12 +0300 Subject: [PATCH] Assert object values directly with deep equality Implement depth-equal checking in typeAssert.js. --- typeAssert.js | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/typeAssert.js b/typeAssert.js index 089ca85..7ddb27f 100644 --- a/typeAssert.js +++ b/typeAssert.js @@ -28,8 +28,36 @@ const typeAssertError = (path, message) => { throw new Error(errMsg) } +const deepEqual = (a, b) => { + if (a === b) { + return true + } + if (typeof a !== TypeStrings.Object || typeof b !== TypeStrings.Object) { + return false + } + if (a === null || b === null) { + return false + } + const aIsArray = a.constructor === Array.prototype.constructor + const bIsArray = b.constructor === Array.prototype.constructor + if (aIsArray !== bIsArray) { + return false + } + const aKeys = Object.keys(a) + const bKeys = Object.keys(b) + if (aKeys.length !== bKeys.length) { + return false + } + for (const key of aKeys) { + if (!bKeys.includes(key) || !deepEqual(a[key], b[key])) { + return false + } + } + return true +} + const assertEquals = (path, expected, got) => { - if (expected !== got) { + if (!deepEqual(expected, got)) { typeAssertError(path, `expected value "${expected}", got "${got}"`) } }