Files
lobehub/__mocks__/zustand/traditional.ts
CanisMinor 4fa2ef410f feat: support TTS & STT (#443)
*  feat(tts): Add tts and stt basic features

*  feat(tts): Handle error

* 💄 style(tts): Add alert to error handler

* 🐛 fix(tts): Error display

* ♻️ refactor: refactor the openai initial code to the createBizOpenAI

* ♻️ refactor(tts): Refactor header config

*  feat: Add TTS voice preview

* 🐛 fix(tts): Fix header

* 🐛 fix: Fix api

---------

Co-authored-by: Arvin Xu <arvinx@foxmail.com>
2023-11-19 21:43:58 +08:00

26 lines
842 B
TypeScript

import { act } from 'react-dom/test-utils';
import { beforeEach } from 'vitest';
import { createWithEqualityFn as actualCreate } from 'zustand/traditional';
// a variable to hold reset functions for all stores declared in the app
const storeResetFns = new Set<() => void>();
// when creating a store, we get its initial state, create a reset function and add it in the set
const createImpl = (createState: any) => {
const store = actualCreate(createState, Object.is);
const initialState = store.getState();
storeResetFns.add(() => store.setState(initialState, true));
return store;
};
// Reset all stores after each test run
beforeEach(() => {
act(() => {
for (const resetFn of storeResetFns) {
resetFn();
}
});
});
export const createWithEqualityFn = (f: any) => (f === undefined ? createImpl : createImpl(f));