Skip to content

Commit

Permalink
Fixed change finding bug (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
AsyncBanana committed Nov 8, 2021
1 parent 6fa6387 commit a5559b5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 16 additions & 0 deletions tests/arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

0 comments on commit a5559b5

Please sign in to comment.