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

Testing code using an Axios instance #78

Closed
gusbmurphy opened this issue Jan 21, 2022 · 2 comments
Closed

Testing code using an Axios instance #78

gusbmurphy opened this issue Jan 21, 2022 · 2 comments

Comments

@gusbmurphy
Copy link

gusbmurphy commented Jan 21, 2022

Hi everyone,

I've been looking online for some guidance on how to test code that is calling an instance of Axios rather than just something like axios.post(...), and am really at a loss. I've been using this library, which is fantastic, but am really stuck here and feel like I might be missing something. An example of the code I'm trying to test could look like this:

const axiosInstance = axios.create({
  baseUrl: "https://www.abc.dev/api"
});

axiosInstance.get("/list");

My impulse to test code like this would be to mock the return value of axios.create, is that necessary? Is there something in this library that I'm missing that would be useful there? Thanks very much for your time, and my apologies if this isn't the best place to ask for advice on this. I should also note that I'm working with TypeScript if that's helpful.

@ryanrhee
Copy link

jest-mock-axios would need a way to instantiate mock AxiosInstance instances, which I don't think is yet implemented. see my comment on another issue

@kingjan1999
Copy link
Collaborator

Hi,

sorry for the late response and thanks for raising the issue. As @ryanrhee already mentioned, this is already being "discussed" (well, it is a bit stale right now) in #59. Thus, I will close this issue and try to revive the other thanks.

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

No branches or pull requests

3 participants