【发布时间】:2020-02-13 16:20:38
【问题描述】:
const expect = require("chai").expect;
class Test
{
constructor(){ this.x= 10;}
run() {
describe("test goes here", function() {
it("sample test", function() {
expect(this.x).to.be.eq(10);
});
});
}
}
new Test().run();
得到 x 是未定义的。
问题:this里面的describe指向完成不同的上下文,如何使x可用于摩卡测试中的this
【问题讨论】:
标签: javascript node.js mocha.js