Skip to content

Commit

Permalink
chore: reproduction test for #53
Browse files Browse the repository at this point in the history
  • Loading branch information
joebobmiles committed Jul 3, 2023
1 parent 9b6014f commit 7b01c52
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
21 changes: 19 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"@types/ws": "^7.4.7",
"eslint": "^7.30.0",
"husky": "^7.0.1",
"immer": "^10.0.2",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"react-test-renderer": "^17.0.2",
Expand Down
33 changes: 33 additions & 0 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { act, renderHook, } from "@testing-library/react-hooks";

import { createStore as createVanilla, } from "zustand/vanilla";
import { create, } from "zustand";
import { immer, } from "zustand/middleware/immer";

import * as Y from "yjs";
import { WebsocketProvider, } from "y-websocket";
Expand Down Expand Up @@ -907,3 +908,35 @@ describe("Yjs middleware in React", () =>
expect(result2.current.count).toBe(1); // Actual issue
});
});

describe("Yjs middleware composed with Immer middleware", () =>
{
describe("When modifying objects", () =>
{
it("Does not crash with non-extensible error on local update.", () =>
{
type Store =
{
names: string[],
addName: (name: string) => void
};

const store = createVanilla<Store>()(immer(yjs(
new Y.Doc(),
"hello",
(set) =>
({
"names": [],
"addName": (name: string) =>
set((state) =>
state.names.push(name)),
})
)));

expect(() =>
{
store.getState().addName("Alice");
}).not.toThrow();
});
});
});

0 comments on commit 7b01c52

Please sign in to comment.