Skip to content

Commit

Permalink
✅ test: Objects nested in arrays are patched
Browse files Browse the repository at this point in the history
  • Loading branch information
joebobmiles committed Jul 12, 2021
1 parent 5d754a9 commit 9935448
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/patching.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,4 +475,53 @@ describe("patchStore", () =>

expect((store.getState().foo[1] as number[])[1]).toBe(3);
});

it("Applies additions to objects nested in arrays.", () =>
{
const store = create(() =>
({
"foo": [ { "bar": 1, } ],
}));

const update = {
"foo": [ { "bar": 1, "baz": 2, } ],
};

patchStore(store, update);

expect(((store.getState().foo[0] as unknown) as { "baz": number }).baz)
.toBe(2);
});

it("Applies updates to objects nested in arrays.", () =>
{
const store = create(() =>
({
"foo": [ { "bar": 1, "baz": 1, } ],
}));

const update = {
"foo": [ { "bar": 1, "baz": 2, } ],
};

patchStore(store, update);

expect(store.getState().foo[0].baz).toBe(2);
});

it("Applies deletions to objects nested in arrays.", () =>
{
const store = create(() =>
({
"foo": [ { "bar": 1, "baz": 1, } ],
}));

const update = {
"foo": [ { "bar": 1, } ],
};

patchStore(store, update);

expect(store.getState().foo[0].baz).toBeUndefined();
});
});

0 comments on commit 9935448

Please sign in to comment.