connect ECONNREFUSED when i use msw with react-testing-library
See original GitHub issueEnvironment
Name | Version |
---|---|
msw | ^0.21.2 |
node | v12.18.3 |
OS | W10 |
Request handlers
const server = setupServer(
rest.post("http://localhost:3100/users", (req, res, ctx) => {
return res(
ctx.json({ message: 'Usuário registrado com sucesso!' }),
ctx.status(200)
);
})
);
beforeAll(() => server.listen())
afterEach(() => server.resetHandlers())
afterAll(() => server.close())
My test call one function that make a http request:
test("should register user successfully when all fields is correctly filled", async () => {
`fireEvent.click(registerButton);`
})
That calls:
const registerUser = async (
user: IRegisterUser
): Promise<AxiosResponse<IRequestResponse>> => {
const api = axios.create({
baseURL: "http://localhost:3100",
});
return await api.post("/users", user);
};
I’m receiving this error:
Error: Error: connect ECONNREFUSED 127.0.0.1:3100
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
connect ECONNREFUSED when using msw with react-testing ...
Jest executes all describe handlers in a test file before it executes any of the actual tests. This is another reason to do...
Read more >connect ECONNREFUSED when integration testing a Node.js ...
In an express.js app that I was integration testing using Mocha the tests suddenly started acting weird ... "before all" hook: Error: connect...
Read more >Frequently asked questions - Mock Service Worker Docs
However, you can use Mock Service Worker in your React Native project for unit and integration tests that run in Node.
Read more >connect econnrefused 127.0.0.1:80 - You.com | The AI Search ...
React : JSDOM 13 Error: Error: connect ECONNREFUSED 127.0.0.1:80 ... import '@testing-library/jest-dom/extend-expect'; // configure msw import server from '.
Read more >React-Testing-Library - What do you guys use to mock HTTP ...
I tried: axios-mock-adapter Axios test fails when you use a proxy in your package.json. Error: connect ECONNREFUSED 127.0.0.1:80 Other then ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @veronesecoms thanks for raising this 😄
Have you tried to use
onUnhandledRequest
option to understand if you have configured your handler well?You can add the option in this way
If this is not useful for your case, could I ask you to create a reproduction repo ? I can help you better.
Thank you so much
Im still getting this error. This is a repo which re produces the error. If anyone could help me, that would be awesome ❤️ https://github.com/charitha95/msw-test