Skip to content

How to strictly match expectations number or order? #41

@pandaiolo

Description

@pandaiolo

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions