Skip to content

How to mock createWithEqualityFn with Vitest? #2691

Closed Answered by goliney
goliney asked this question in Q&A
Discussion options

You must be logged in to vote

I came up with this:

// __mocks__/zustand/traditional.ts

import { act } from "@testing-library/react";
import type { StateCreator } from "zustand";
import type * as zustandTraditional from "zustand/traditional";

const { createWithEqualityFn: actualCreateWithEqualityFn } =
  await vi.importActual<typeof zustandTraditional>("zustand/traditional");

// a variable to hold reset functions for all stores declared in the app
export const storeResetFns = new Set<() => void>();

const createWithEqualityFnUncurried = <T>(stateCreator: StateCreator<T>) => {
  const store = actualCreateWithEqualityFn(stateCreator);
  const initialState = store.getInitialState();
  storeResetFns.add(() => {
    store.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@dbritto-dev
Comment options

Answer selected by goliney
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants