Axios.create is not a function
See original GitHub issueHi @ctimmerm,
I’m having an “axios.create() is not a function error” when i try to use axios-mock-adapter. Here’s the implementation. `
import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
let mock = new MockAdapter(axios);
mock.onGet('https://myapi.org/v1/', { params: { param1: 'holiday', sortBy:'top' } }).reply(200, {
data: [{
author: "Vivian Michaels",
}]
});
axios.get('https://myapi.org/v1/', { params: { param1: 'holiday', sortBy:'top' } })
.then(function(response) {
console.log(response.data);
});`
I’m doing exactly as the documentation says but then i get the error: TypeError: axios.create is not a function. Any help is appreciated.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:30
- Comments:15 (1 by maintainers)
Top Results From Across the Web
Why TypeError: axios.create is not a function? When testing ...
This problem typically happens when you are already mocking axios (very likely within a __mocks__ folder. With jest, you can explicitly unmock, ...
Read more >axios.create is not a function · Issue #5052 - GitHub
Hello to you, I am creating this ticket because I have a problem with the latest version of your package released a few...
Read more >How to use the axios.default function in axios - Snyk
To help you get started, we've selected a few axios.default examples, based on popular ways it is used in public projects.
Read more >Why TypeError: axios.create is not a function ... - iTecNote
I'm trying to test my axios API functions in React. Found this question here: how do i test axios in jest which pointed...
Read more >Understanding Axios.create - LogRocket Blog
Axios.create is a handy feature within Axios used to create a new instance with a custom configuration. With Axios.create, we can generate a ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@StanSarr im just mocking it via jest mock, i have created file
axios.jsin__mocks__folder and jest mock it automatically, then you can import axios in you tests and spy on it or make another mock implementation to test different responses.edit: i didnt managed to make it work with this lib, even when i removed jest mock. only reason i was looking for alternative is that i didnt notice that someone who wrote this jest mock didnt use jest.fn() and i thought i cant mock any responses.
Adding this here since it’s the first hit on google to the question.
With jest, you can explicitly unmock, then call this library.
This library gives nice, flexible apis when working with external requests. However it doesn’t globally prevent your app from making external calls that can be triggered by a test in a different component.
So I found both using this library and doing a manual mock in the
__mocks__folder equally helpful.