Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(docs): support currying for testing mock #2137

Merged
merged 4 commits into from
Oct 22, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
change function name
  • Loading branch information
ha1fstack committed Oct 22, 2023
commit 30736f832b40fea6f1225fc8d4216c15fbce0ffe
24 changes: 12 additions & 12 deletions docs/guides/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const { create: actualCreate, createStore: actualCreateStore } =
// a variable to hold reset functions for all stores declared in the app
export const storeResetFns = new Set<() => void>()

const createInternalFn = <T>(stateCreator: zustand.StateCreator<T>) => {
const createUncurried = <T>(stateCreator: zustand.StateCreator<T>) => {
const store = actualCreate(stateCreator)
const initialState = store.getState()
storeResetFns.add(() => {
Expand All @@ -92,11 +92,11 @@ export const create = (<T>() => {

// to support curried version of create
return typeof stateCreator === "function"
? createInternalFn(stateCreator)
: createInternalFn
? createUncurried(stateCreator)
: createUncurried
}) as typeof zustand.create

const createStoreInternalFn = <T>(stateCreator: zustand.StateCreator<T>) => {
const createStoreUncurried = <T>(stateCreator: zustand.StateCreator<T>) => {
const store = actualCreateStore(stateCreator)
const initialState = store.getState()
storeResetFns.add(() => {
Expand All @@ -111,8 +111,8 @@ export const createStore = (<T>(stateCreator: zustand.StateCreator<T>) => {

// to support curried version of createStore
return typeof stateCreator === "function"
? createStoreInternalFn(stateCreator)
: createStoreInternalFn
? createStoreUncurried(stateCreator)
: createStoreUncurried
}) as typeof zustand.createStore

// reset all stores after each test run
Expand Down Expand Up @@ -166,7 +166,7 @@ const { create: actualCreate, createStore: actualCreateStore } =
// a variable to hold reset functions for all stores declared in the app
export const storeResetFns = new Set<() => void>()

const createInternalFn = <T>(stateCreator: zustand.StateCreator<T>) => {
const createUncurried = <T>(stateCreator: zustand.StateCreator<T>) => {
const store = actualCreate(stateCreator)
const initialState = store.getState()
storeResetFns.add(() => {
Expand All @@ -181,11 +181,11 @@ export const create = (<T>() => {

// to support curried version of create
return typeof stateCreator === "function"
? createInternalFn(stateCreator)
: createInternalFn
? createUncurried(stateCreator)
: createUncurried
}) as typeof zustand.create

const createStoreInternalFn = <T>(stateCreator: zustand.StateCreator<T>) => {
const createStoreUncurried = <T>(stateCreator: zustand.StateCreator<T>) => {
const store = actualCreateStore(stateCreator)
const initialState = store.getState()
storeResetFns.add(() => {
Expand All @@ -200,8 +200,8 @@ export const createStore = (<T>(stateCreator: zustand.StateCreator<T>) => {

// to support curried version of createStore
return typeof stateCreator === "function"
? createStoreInternalFn(stateCreator)
: createStoreInternalFn
? createStoreUncurried(stateCreator)
: createStoreUncurried
}) as typeof zustand.createStore

// reset all stores after each test run
Expand Down
Loading