MSW doesn't work in the project #1616
Replies: 2 comments
-
whooh i dont know |
Beta Was this translation helpful? Give feedback.
-
Hi, @orchidenver. I looked at the repo you linked, here's my feedback. Resolve test setup errorsI've noticed you get quite a number of errors while running tests. Mainly this:
These usually point at incorrectly constructed tests in regards to how you render React. Please research those online and resolve them. Having them may affect how your components are rendered, also affecting whether they make requests as you expect. Cover unhandled endpointsMSW communicates to you that you have requests to endpoints you don't have covered with request handlers:
For example, you make the request above in Please add request handlers for those requests to have your components working correctly (receiving the responses they expect). Follow MSW suggestionsMSW also prints a warning that you're including query parameters in the request handlers' URLs:
That doesn't really affect how MSW works because it strips them away before performing request matching. Please follow the instructions and remove query parameters from the request handlers' URLs. The instructions also mention how to access those query parameters in the handler if you need to. You can learn more about working with Query parameters in the documentation. I believe once you address all these points, your tests should pass. |
Beta Was this translation helpful? Give feedback.
-
Hello guys! I try to test my weather app with MSW and I'm stuck. Please help me to understand what do I do wrong?
I defined handlers and server, also added beforeAll, afterEach and afterAll in setupTests. I try to test my async API call, but it looks like my app totally ignores my test because received value equals the value I passed in my useEffect in component Form.tsx.
My repo with branch "test"
https://github.com/orchidenver/weather-app-react/tree/test
My Form Component
My App.test.tsx:
My handlers:
Beta Was this translation helpful? Give feedback.
All reactions