Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/463.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Jest测试api创建自己的上下文节点js_Javascript_Node.js_Jestjs - Fatal编程技术网

Javascript Jest测试api创建自己的上下文节点js

Javascript 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

我正在节点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 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中添加文件。此文件将在测试开始之前运行