Skip to content

Commit

Permalink
chore: added test for scenario reported by #53
Browse files Browse the repository at this point in the history
  • Loading branch information
joebobmiles committed Jul 3, 2023
1 parent 7b01c52 commit 3e09c84
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,7 @@ describe("Yjs middleware in React", () =>

describe("Yjs middleware composed with Immer middleware", () =>
{
// See issue 53
describe("When modifying objects", () =>
{
it("Does not crash with non-extensible error on local update.", () =>
Expand Down Expand Up @@ -938,5 +939,58 @@ describe("Yjs middleware composed with Immer middleware", () =>
store.getState().addName("Alice");
}).not.toThrow();
});

it("Does not crash with non-extensible error on peer update.", () =>
{
type Store =
{
names: string[],
addName: (name: string) => void
};

const docA = new Y.Doc();
const docB = new Y.Doc();

docA.on("update", (update: any) =>
{
Y.applyUpdate(docB, update);
});
docB.on("update", (update: any) =>
{
Y.applyUpdate(docA, update);
});

const storeName = "store";

createVanilla<Store>()(immer(yjs(
docA,
storeName,
(set) =>
({
"names": [] as Array<string>,
"addName": (name: string) =>
set((state) =>
state.names.push(name)),
})
)));

const storeB = createVanilla<Store>()(immer(yjs(
docB,
storeName,
(set) =>
({
"names": [],
"addName": (name: string) =>
set((state) =>
state.names.push(name)),
})
)));

expect(() =>
{
storeB.getState().addName("Alice");
// Peer A should not throw an error.
}).not.toThrow();
});
});
});

0 comments on commit 3e09c84

Please sign in to comment.