I have axios and axios-mock-adapter installed in my nextjs app, but when the Axios request running in localhost:3000 tries to call an AWS Lambda request (that I know works), I'm getting the error:
Goals (get) api error: TypeError: mockAdapter.originalAdapter is not a function
The request is within a useEffect hook - and stopping at the catch error:
useEffect(() => {
const getGoals = async () => {
try {
const response = await api.get(apiUrl)
setGoals(response.data.body)
} catch (error) {
console.log('Goals (get) api error:', error)
}
}
getGoals()
})
where api is imported from here:
import axios from 'axios'
export default axios.create({
baseURL: 'https://xxxxxxxxxx.execute-api.us-east-2.amazonaws.com/test'})
The mock adapter is in a separate component:
import axios from 'axios'
import MockAdapter from 'axios-mock-adapter'
const mock = new MockAdapter(axios)
export default mock
I don't understand (and never had this issue) why my real axios request is getting confused with the mock request. I've run both in parallel before, and I want to continue to use axios-mock-adapter for my jest tests.
Why does my api.get in my useEffect fail?
Issue addressed here, per user "teetotum" comment this is due to versions.
using "axios": "1.1.3"
will help to resolve issue for the moment.