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

Mocking thunk calls from another thunk #715

Open
DanielPe05 opened this issue Dec 6, 2021 · 0 comments
Open

Mocking thunk calls from another thunk #715

DanielPe05 opened this issue Dec 6, 2021 · 0 comments

Comments

@DanielPe05
Copy link

Testing a thunk that calls an action is very simple, using the mockActions helper, however, this becomes very difficult when testing that a thunk calls another thunk.
It is common practice for large stores to dispatch other thunks when something happens inside your thunk. This is possible using getStoreActions. When testing this behavior since mockActions doesn't prevent the call to the other thunk I'm having to include other store models to satisfy my test. This feels bad every time I run into it, like the boundaries of my test are not well defined. for example:

const { getActions, getMockedActions } = createStore(
  myModel,
  { mockActions: true }
)

await getActions().someThunk()

expect(getMockedActions()).toContainEqual({
  payload: undefined,
  type: '@thunk.someOtherModel.someOtherThunk(start)'
})

I would expect the above to pass but it fails because the model actually calls the thunk. You end up having to do something like this:

const { getActions, getState } = createStore(
  { myModel, someOtherModel }
)

await getActions().myModel.someThunk()

expect(getState().someOtherModel.expectedState).toEqual('...')

As more models depend on each other this becomes increasingly difficult to maintain. Not sure if there is a workaround for this in place or if there is a plan to support this in the future. I'd be happy to contribute something like this if I get some high-level direction on how to accomplish it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

1 participant