【发布时间】:2022-02-10 19:18:02
【问题描述】:
比如我无法访问这个模块,为什么?
let nodeCacheClient;
module.exports = {
initNodeCache: () => {
const NodeCache = require("node-cache");
nodeCacheClient = new NodeCache();
return nodeCacheClient;
},
insertToCacheWithTtl: (key, obj, ttl) => {
return nodeCacheClient.set(key, obj, ttl);
},
getCache: (key) => {
return nodeCacheClient.get(key);
},
deleteKey: (key) => {
return nodeCacheClient.del(key);
},
};
当我运行这个测试时,我得到这个:TypeError: Cannot read property 'get' of undefined Error
test("login a user", async () => {
try {
const response = await axiosInstance.post("users/login", {
email: "test@gmail.com",
password: "144847120",
otpCode: getCacheClient.getCache("test@gmail.com")
});
console.log(response.data);
expect(response.data.status).toBe("success");
} catch (error) {
console.log(error + " Error");
expect(error);
}
});
【问题讨论】:
-
除了您向我们展示的内容之外,您的测试不包含其他内容?
-
@AhmadMOUSSA 真正的问题是为什么我的导出模块无法访问开玩笑测试?
-
您的问题是“为什么您的导出模块无法访问 jest 测试”或“为什么您的导出模块无法从 jest 测试中访问”?
标签: javascript testing jestjs nodes ts-jest