Closed chalist closed 4 years ago
Could be that you have imported the libraries incorrectly. Try:
import axios from 'axios'
import MockAdapter from 'axios-mock-adapter'
const mockAdapter = new MockAdapter(axios)
import { randomString } from "@/Components/Tools/StringTools";
const data = [{ id: 1, name: "John Smith", token: "fjhgyklasjdhnaksdbnasdbajsdghabsdhjgtavsudytqwve897a6sdbaishdgb" }];
// jest.mock("axios"); --> no need to do this
import { ApiService } from "../api.service";
import axios from 'axios' import MockAdapter from 'axios-mock-adapter' const mockAdapter = new MockAdapter(axios)
Still happening
TypeError: Cannot read property 'defaults' of undefined
at Object.<anonymous> (node_modules/axios-mock-adapter/src/utils.js:9:39)
at Object.<anonymous> (node_modules/axios-mock-adapter/src/handle_request.js:3:13)
Into the utils.js file the line problem is
// < 0.13.0 will not have default headers set on a custom instance
var rejectWithError = !!axios.create().defaults.headers;
My axios version is "axios": "0.21.1",
.
It is happening with me too.
I fixed my problemn. It was because I wrote the code jest.mock('axios'). I removed this and everything works normally.
Thank you, @Bernardoow, that fixed my problem too :D
@jose920405 Tell me, did you manage to solve the problem?
I got this error for importing
axios-mock-adapter
:I searched, but I cant find anything about this error.
api.service.test.js:
I don't know where I make mistake!