From a5559b5ad27e8740d88a526fdebb0fa2a895eb09 Mon Sep 17 00:00:00 2001 From: AsyncBanana Date: Mon, 8 Nov 2021 18:53:51 -0500 Subject: [PATCH] Fixed change finding bug (#11) --- index.ts | 2 +- tests/arrays.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/index.ts b/index.ts index d37f8fd..99ada95 100644 --- a/index.ts +++ b/index.ts @@ -25,7 +25,7 @@ export default function diff( !richTypes[Object.getPrototypeOf(obj[key]).constructor.name] && !stack.includes(obj[key]) ) { - const nestedDiffs = diff(obj[key], newObj[key], stack.concat(obj[key])); + const nestedDiffs = diff(obj[key], newObj[key], stack.concat([obj[key]])); diffs.push( ...nestedDiffs.map((difference) => { difference.path.unshift(key); diff --git a/tests/arrays.js b/tests/arrays.js index c32d837..987e651 100644 --- a/tests/arrays.js +++ b/tests/arrays.js @@ -21,4 +21,20 @@ test("nested array", () => { ]); }); +test("object in array in object", () => { + assert.equal( + diff( + { test: ["test", { test: true }] }, + { test: ["test", { test: false }] } + ), + [ + { + type: "CHANGE", + path: ["test", "1", "test"], + value: false, + }, + ] + ); +}); + test.run();