相关疑难解决方法(0)

Mocha'this'在之前和之前都是钩子

使用Mocha.js编写的以下测试代码失败.我希望someVal在最后一次测试中增加3倍并且等于3.这个问题出现在更复杂的场景中,我使用外部块之前的值设置在内部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);
    });
  });
});
Run Code Online (Sandbox Code Playgroud)

javascript mocha.js

10
推荐指数
2
解决办法
5671
查看次数

标签 统计

javascript ×1

mocha.js ×1