Merge pull request #1777 from Molecule-AI/fix/canvas-mock-staging
fix(canvas): add getState to useCanvasStore mock in ContextMenu test
This commit is contained in:
commit
842a7daf4c
@ -48,11 +48,20 @@ const mockStore = {
|
||||
nodes: [] as Array<{ id: string; data: { parentId: string | null } }>,
|
||||
};
|
||||
|
||||
vi.mock("@/store/canvas", () => ({
|
||||
useCanvasStore: vi.fn(
|
||||
(selector: (s: typeof mockStore) => unknown) => selector(mockStore)
|
||||
),
|
||||
}));
|
||||
// useCanvasStore.getState() is called directly by ContextMenu to read `nodes`
|
||||
// for parent-filtering (see ContextMenu.tsx childNodes computation). The mock
|
||||
// must expose both the selector-calling function form AND the .getState()
|
||||
// form so production code using either pattern doesn't hit "not a function".
|
||||
// Factory body runs under vi.mock's hoist — cannot reference outer scope,
|
||||
// so we build the mock function inside and reach `mockStore` via `globalThis`.
|
||||
vi.mock("@/store/canvas", () => {
|
||||
const fn = vi.fn((selector: (s: typeof mockStore) => unknown) =>
|
||||
selector(mockStore),
|
||||
);
|
||||
return {
|
||||
useCanvasStore: Object.assign(fn, { getState: () => mockStore }),
|
||||
};
|
||||
});
|
||||
|
||||
// ── Component under test — imported AFTER mocks ───────────────────────────────
|
||||
import { ContextMenu } from "../ContextMenu";
|
||||
|
||||
Loading…
Reference in New Issue
Block a user