Skip to content
Discussion options

You must be logged in to vote

Hi, @wslp12. Here's what I suggest.

  1. Drop the fetch mock entirely.
  2. To count the number of requests, do that in the matching request handler from MSW:
test('your test', () => {
  let requestCallCount = 0

  server.use(
    http.get('/some-url', () => {
      requestCallCount++
      // ...handle or passthrough this request.
    })
  )
})

You can return nothing from a request handler. In that case, MSW will try to look up another matching handler for the same request. If it finds none, the request will be performed as-is. That is likely not what you want in tests because you always want to mock the network and focus on what your network-dependent logic is doing (like counting request calls…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by wslp12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants