Skip to content
Discussion options

You must be logged in to vote

What I ended up doing was changing my axios({ calls to axios.request({, and then I was able to mock like this:

vi.mock("axios");
const mockedAxios = vi.mocked(axios, true);

// further down in the test
mockedAxios.request.mockImplementation(({ url }) => {
  switch(url) {
    case "www.some-url.com":
      return Promise.resolve({ data: [] });
    default:
      return Promise.resolve({ data: {} });
  }
});

Not sure if simply calling axios({ is a bad practice, but being able to sub in request and get my desired outcome has fixed my issues.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by incutonez
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant