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

How to strictly match expectations number or order? #41

Open
pandaiolo opened this issue Nov 23, 2020 · 1 comment
Open

How to strictly match expectations number or order? #41

pandaiolo opened this issue Nov 23, 2020 · 1 comment

Comments

@pandaiolo
Copy link

pandaiolo commented Nov 23, 2020

Another question regarding testing order and number of triggered actions.

Let's say I have a search() action that triggers searchLoading() and then searchResults().

If a search action is coming before the previous is finished, it cancels it (that would happen when typing in a search box, for example)

I would like to do the following:

it('cancels the previous call if any', async done => {
  const dispatchThreeSearches = () => async dispatch => {
    dispatch(searchBidders({ keyword: 'test1' }))
    dispatch(searchBidders({ keyword: 'test2' }))
    await dispatch(searchBidders({ keyword: 'test3' }))
  }
  expect(dispatchThreeSearches())
    .toDispatchActions([
      searchLoading(),
      searchLoading(),
      searchLoading(),
      searchResults({ results: mockedResultsForTest3Keyword })
    ])
})

After a few tests of the above code, it appears that each action is matched independently of the others, which means it is not possible to test:

  1. Order of dispatched actions
  2. Number of dispatching of the same action (I could put 100's of searchLoading() and it would still pass)

Do you see a way to achieve a more fine grained control over expected actions?

Thanks!

@dmitry-zaets
Copy link
Member

Hi,
Excuse me for the late response.

  1. I'm not sure, but I think you can't test the order of the functions (but should be relatively easy to add a flag for this type of functionality)
  2. The events would be removed from the list of available actions. So if you dispatch only one action of a certain type, if you call the assertion with two items expected - it should fail. Here is a code of the implementation for reference:
    https://github.com/redux-things/redux-actions-assertions-js/blob/78a5fefba99034d38b6454731cc5b167e100e373/src/asserts/utils/assertDispatchedActions.js#L11

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

No branches or pull requests

2 participants