Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doc improvement suggestion: extra settings needed if using axios v1.5.0 in vitest/jest #1747

Closed
1 task
zoltan-nz opened this issue Sep 24, 2023 · 2 comments
Closed
1 task
Labels

Comments

@zoltan-nz
Copy link

Scope

Improves an existing behavior

Compatibility

  • This is a breaking change

Feature description

Axios' latest version changed the underlying adapter configuration.

Using axios v1.5.0 with msw needs an extra line of code in the test setup.

For example: setup-tests.ts

import axios from 'axios'
import { afterAll, afterEach, beforeAll } from 'vitest'
import { server } from './mocks/server'

beforeAll(() => {
  axios.defaults.adapter = 'xhr'
  server.listen({ onUnhandledRequest: 'warn' })
})

afterEach(() => server.resetHandlers())
afterAll(() => server.close())

Have to use axios.defaults.adapter = 'xhr'. Otherwise, msw interception would not work.

Source: axios/axios#5844

@kettanaito
Copy link
Member

Hi, @zoltan-nz. Thanks for raising this.

MSW should intercept Axios requests regardless which adapter you're using. Can you please submit a reproduction repository when it fails to do so? We've got some integration tests with Axios, I'd love to add your use case to them to prevent issues like this. Thanks.

@zoltan-nz
Copy link
Author

@kettanaito Thank you! Meanwhile, Axios fixed the issue, and with axios v1.5.1 everything is back to normal. ;)

axios/axios#5837

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants