Я получаю ошибку ниже при написании модульного теста моей функции.
(0 , _service.createUser) is not a function
TypeError: (0 , _service.createUser) is not a function
at _callee$ (https://pbz00.csb.app/src/service.test.js:43:44)
at tryCatch (https://pbz00.csb.app/node_modules/regenerator-runtime/runtime.js:62:40)
at Generator.invoke [as _invoke] (https://pbz00.csb.app/node_modules/regenerator-runtime/runtime.js:288:22)
at Generator.prototype.<computed> [as next] (https://pbz00.csb.app/node_modules/regenerator-runtime/runtime.js:114:21)
вот моя функция
export const createUser = async values => {
try {
const response = await axios.post("http:/10.13.15.245:3000/create", {
values
});
console.log("response", response);
if (response && response.data && response.data.status.code === "200") {
abc = true;
return abc;
}
} catch (e) {
if (e.response && e.response.data) {
console.log(e.response.data.message);
}
}
};
Я хочу проверить это возвращаемое значение true
или undefined
.
вот мой код https://codesandbox.io/s/busy-galois-pbz00
import { createUser } from "./service.test";
describe("service test", () => {
it("check abc value", async () => {
const axios = {
post: jest.fn(() =>
Promise.resolve({
data: {
greeting: "hello there",
status: {
code: "200"
}
}
})
)
};
console.log("createUser", createUser);
let abc = await createUser();
console.log("after createUser", abc);
expect(abc).toBe(true);
});
});
import { createUser } from "./service";
describe("service test", () => {
it("check abc value", async () => {
jest.spyOn(axios, "post").mockImplementation(() =>
Promise.resolve({
data: {
greeting: "hello there",
status: {
code: "200"
}
}
})
);
console.log("createUser", createUser);
let abc = await createUser();
console.log("after createUser", abc);
expect(abc).toBe(true);
});
});
обновлено
import { createUser } from "./service";
import axios from "axios";
describe("service test", () => {
it("check abc value", async () => {
jest.spyOn(axios, "post").mockImplementation(() =>
Promise.resolve({
data: {
greeting: "hello there",
status: {
code: "200"
}
}
})
);
console.log("createUser", createUser);
let abc = await createUser();
console.log("after createUser", abc);
expect(abc).toBe(true);
});
});