Problem to mock zustand #2343
Answered
by
dbritto-dev
pedrohamarques
asked this question in
Q&A
-
Hello, everyone I'm trying to mock zustand in a small project using React Native and I'm having difficulty to do so. Here's my store, where export const useCartStore = create(
persist<StateProps>(
(set) => ({
products: [],
add: (product: ProductProps) =>
set((state) => ({
products: cartInMemory.add(state.products, product),
})),
remove: (productId: string) =>
set((state) => ({
products: cartInMemory.remove(state.products, productId),
})),
clear: () =>
set(() => ({
products: [],
})),
}),
{
name: 'iFud:cart',
storage: createJSONStorage(() => AsyncStorage),
},
),
); I followed the documentation to mock zustand in Herés the log I receive:
And here's my packages versions:
I don't know if the problem is in the mock or in the tests setup. I'd appreciate the help |
Beta Was this translation helpful? Give feedback.
Answered by
dbritto-dev
Feb 16, 2024
Replies: 1 comment 8 replies
-
@pedrohamarques would you mind sharing us a minimal repro on stackblitz? |
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@pedrohamarques the setup is a bit tricky talking about react native and other stuff but seems the issue is coming from AsyncStorage itself but here's the fix -> https://stackblitz.com/edit/vitejs-vite-fqgbku?file=src%2Fstores%2Fcart-store.ts