Replies: 1 comment 4 replies
-
Hey, @olegKusov. We have a recipe on Request assertions in our docs. In short, you rarely need to assert on requests directly and should consider testing the logic/UI that derives from the successful (or unsuccessful) response. There are cases, however, when you need to assert the request directly. For example, when a request is internal (analytics, metrics) or has no logic derived from it. In those rare scenarios you can leverage the life-cycle events API to await the request and assert on it: import { setupServer } from 'msw/node'
const server = setupServer(...)
/* Your regular MSW setup here in "beforeAll"/"afterAll"... */
it('sends the correct Google Analytics payload', (done) => {
doStuff()
// Listen to all requests that match a defined request handler.
server.on('request:match', (request) => {
expect(request.body).toEqual(myData)
done()
})
}) |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I need somehow to get req data in my test
Example:
Is it possbile? Because I have a lot of mess in my component with local state, wich can be changed with side effects. And I need to be sure that data sends correctly.
Beta Was this translation helpful? Give feedback.
All reactions