Javascript Jest测试api创建自己的上下文节点js
我正在节点js中使用jest进行测试 我的文件index.jsJavascript Jest测试api创建自己的上下文节点js,javascript,node.js,jestjs,Javascript,Node.js,Jestjs,我正在节点js中使用jest进行测试 我的文件index.js const config = helper.config; const _ = helper.module._; 它抛出错误 helper is not defined. 这里的助手是全局对象 我的笑话 const assign = require('xxxxxx/index'); const body = {} describe("forgotPassword()", () => { it("should r
const config = helper.config;
const _ = helper.module._;
它抛出错误
helper is not defined.
这里的助手是全局对象
我的笑话
const assign = require('xxxxxx/index');
const body = {}
describe("forgotPassword()", () => {
it("should return true", () => {
//Testing a boolean
expect(assign(body)).toBeTruthy();
//Another way to test a boolean
expect(assign(body)).toEqual(true);
});
});
有什么办法吗?我找到了答案 我想在运行测试之前运行一些文件 将此添加到
package.json
"jest": {
"setupFiles": ["./app.js"]
}
在setupFiles中添加文件。此文件将在测试开始之前运行