箭头函数

优质
小牛编辑
127浏览
2023-12-01

不鼓励将箭头函数(“lambdas”)传递给 Mocha。Lambdas词法绑定 this,无法访问 Mocha 上下文。例如,以下代码将失败:

describe('my suite', () => {
it('my test', () => {
  // should set the timeout of this test to 1000 ms; instead will fail
  this.timeout(1000);
  assert.ok(true);
});
});

如果您不需要使用 Mocha 的上下文,lambdas应该可以工作。但是,如果最终需要,结果将更难以重构。