【发布时间】:2014-12-08 12:44:13
【问题描述】:
以下使用Mocha.js 编写的测试代码失败。我希望 someVal 在最后一次测试中增加 3 倍并等于 3。这个问题出现在更复杂的场景中,我使用外部 before 块中设置的值在内部 beforeEach 块中设置另一个值。简化案例:
describe('increasing 3 times', function() {
before(function() {
this.instanceThis = this;
return this.someVal = 0;
});
beforeEach(function() {
return this.someVal += 1;
});
return describe('going deeper', function() {
before(function() {
return this.someVal += 1;
});
beforeEach(function() {
return this.someVal += 1;
});
return it('has increased someVal to 3', function() {
return this.someVal.should.equal(3);
});
});
});
【问题讨论】:
标签: javascript mocha.js