首页 > 解决方案 > 测试用例内部的`before`钩子(`it`)

问题描述

mocha 不允许在it测试用例中使用钩子吗?

我尝试了以下,它似乎永远不会执行:

describe('Array', () => {

  before(async () => {
      // do some async stuff before any test cases in this suite run
      // THIS RUNS OK
  });

  it('should blah', async () => {
      before(async () => {
          // do some async stuff just before this test case
          // THIS NEVER RUNS!!!!!!!!!!!!!!!!!!!!!!
      });

      // blah
  );

});

before立即在运行describe,但before立即在内部it不运行。

标签: mocha.js

解决方案


推荐阅读