Skip to content

Tests No Longer Passing since Upgrading to v1.5.0 #5844

@mdbiscan

Description

@mdbiscan

Describe the bug

After upgrading axios from 1.4.0 to 1.5.0, tests that use network calls all fail consistently.

In my tests, I use Vitetest with Pretender intercepting network calls. None of my network tests pass with axios 1.5.0. I get the following error messages:

  code: 'ECONNREFUSED',
  errors: [
    Error: connect ECONNREFUSED 127.0.0.1:80
        at createConnectionError (node:net:1630:14)
        at afterConnectMultiple (node:net:1660:40) {
      errno: -61,
      code: 'ECONNREFUSED',
      syscall: 'connect',
      address: '127.0.0.1',
      port: 80
    },
    Error: connect ECONNREFUSED ::1:80
        at createConnectionError (node:net:1630:14)
        at afterConnectMultiple (node:net:1660:40) {
      errno: -61,
      code: 'ECONNREFUSED',
      syscall: 'connect',
      address: '::1',
      port: 80
    }
  ],

Can confirm this is from axios. Downgrading back to 1.4.0 resolves the problem.

To Reproduce

Using the last version of Pretender and an axios instance using v1.5.0, attempt to intercept a network call in a test environment, using Jest or Vitest.

Code snippet

No response

Expected behavior

Pretender should be able to intercept network calls in the test environment.

Axios Version

1.5.0

Adapter Version

No response

Browser

No response

Browser Version

No response

Node.js Version

20.4.0

OS

Mac OS 13.4

Additional Library Versions

Pretender 3.4.7
React 18.2.0

Additional context/Screenshots

I use axios by creating an instance within my own service class, like so:


  constructor(config = {}) {
    /** Configuration settings for the service instance */
    this.config = Object.assign(DEFAULT_CONFIG, config);
    
    /** Make axios send cookies withCredentials=true */
    this.ajax = axios.create({
      baseURL: this.baseURL, // a getter method that cleans strings from erroneous slashes
      withCredentials: this.config.withCredentials, // a boolean field
    });
    
    /** Set content type to json */
    this.ajax.defaults.headers.common['Content-Type'] = 'application/json';
  }


The test config for Vite has the baseURL set to `/`. Pretender doesn't allow you to set a URL path. These configurations have not changed. 

Pretender doesn't have much for the config, it's just `new Pretender` instance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions