Skip to content

Commit

Permalink
✅ test: Arrays 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 99fa8be commit 5d754a9
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/patching.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,4 +427,52 @@ describe("patchStore", () =>

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

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

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

patchStore(store, update);

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

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

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

patchStore(store, update);

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

it("Combines additions and deletions as updates to nested arrays.", () =>
{
const store = create(() =>
({
"foo": [ 1, [ 2, 4 ] ],
}));

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

patchStore(store, update);

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

0 comments on commit 5d754a9

Please sign in to comment.