Satoru Kikuchi
Satoru Kikuchi

Reputation: 1199

Test passed but the error message "Error: connect ECONNREFUSED 127.0.0.1:80" shows up

I'm writing test code with Jest and React Testing Library.

The code passes but it shows the error "Error: connect ECONNREFUSED 127.0.0.1:80".

This is the code.


describe('Purchase button', () => {
  test('It should be working and move to complete page', async () => {

:

    // Push 'Submit' button
    act(() => {
      fireEvent.click(getByText(/Submit/));
    })
    expect(spyAPI).toBeCalledWith(`${id}`);
    // Check moving to complete page.
    await waitFor(() => {
      expect(getByText(/Thank you, you have purchased/)).toBeInTheDocument();
    })
:


If the last line is commented out like the following, the error message is not there.

/*
await waitFor(() => {
  expect(getByText(/Thank you, you have purchased/)).toBeInTheDocument();
})
*/

Upvotes: 2

Views: 6735

Answers (1)

Niels Van den Broeck
Niels Van den Broeck

Reputation: 66

EConnectionRefused means there is still an API call which is being executed. I don't know how you spy on yours. The reason it's not there when you comment out your waitFor is because your test exits before you execute it. You probably do get an act warning in that case if you set state after the call.

Upvotes: 4

Related Questions