使用摩卡尝试从testHook文件中导出变量,但在测试文件中未定义,我的代码是::
测试文件:
var xyz = require("testHook").xyz;
class test1 {
execute() {
describe("test suite 1", async () => {
it("test 1", async () => {
console.log(xyz);
});
});
}
}
new test1().execute();
testHook.js
function abc()
{
//do some stuff and assume value to be returned is 10
exports.xyz = 10;;
}
beforeEach(() => {
abc();
console.log(this.xyz);
});
输出::
test suite 1
10
undefined
✓ test 1: 1ms
Suite duration: 0.009 s, Tests: 1
1 passing (10ms)