Node.js Mocha.js:to run“;“之后”;即使试衣失败,也要上钩

Node.js Mocha.js:to run“;“之后”;即使试衣失败,也要上钩,node.js,mocha.js,Node.js,Mocha.js,即使其中一个测试(套件)失败,也可以运行“after”钩子吗?是的,当测试失败时,应同时运行after和after钩子 有关相关讨论和更改,请参见以下github问题:、 下面是一个例子来证明我的主张: describe('test', function() { after(function() { console.log('after'); }); afterEach(function() { console.log('afterEach'); }); it('fails syn

即使其中一个测试(套件)失败,也可以运行“after”钩子吗?

是的,当测试失败时,应同时运行
after
after钩子

有关相关讨论和更改,请参见以下github问题:、

下面是一个例子来证明我的主张:

describe('test', function() {
  after(function() { console.log('after'); });
  afterEach(function() { console.log('afterEach'); });

  it('fails sync', function(done) {
    after(function() { console.log('inner after 1'); });
    throw new Error('failed');
  });

  it('fails async', function(done) {
    after(function() { console.log('inner after 2'); });
    process.nextTick(function() {
      throw new Error('failed');
    });
  });
});
使用摩卡1.1.12产生以下输出:

  ․afterEach
․afterEach
after
inner after 1
inner after 2


  0 passing (5 ms)
  2 failing

1) test fails sync:
 Error: failed
  at Context.<anonymous> (/private/tmp/so/test/main.js:7:11)
  at Test.Runnable.run (/private/tmp/so/node_modules/mocha/lib/runnable.js:194:15)
  at Runner.runTest (/private/tmp/so/node_modules/mocha/lib/runner.js:355:10)
  at /private/tmp/so/node_modules/mocha/lib/runner.js:401:12
  at next (/private/tmp/so/node_modules/mocha/lib/runner.js:281:14)
  at /private/tmp/so/node_modules/mocha/lib/runner.js:290:7
  at next (/private/tmp/so/node_modules/mocha/lib/runner.js:234:23)
  at Object._onImmediate (/private/tmp/so/node_modules/mocha/lib/runner.js:258:5)
  at processImmediate [as _immediateCallback] (timers.js:330:15)

2) test fails async:
 Error: failed
  at /private/tmp/so/test/main.js:13:12
  at process._tickCallback (node.js:415:13)
——每次之后
"以后,
之后
内后1
内后2
0通过(5毫秒)
2失败
1) 测试同步失败:
错误:失败
在上下文中。(/private/tmp/so/test/main.js:7:11)
在Test.Runnable.run(/private/tmp/so/node_modules/mocha/lib/Runnable.js:194:15)
在Runner.runTest(/private/tmp/so/node_modules/mocha/lib/Runner.js:355:10)
at/private/tmp/so/node_modules/mocha/lib/runner.js:401:12
下一步(/private/tmp/so/node_modules/mocha/lib/runner.js:281:14)
at/private/tmp/so/node_modules/mocha/lib/runner.js:290:7
下一步(/private/tmp/so/node_modules/mocha/lib/runner.js:234:23)
at Object._onImmediate(/private/tmp/so/node_modules/mocha/lib/runner.js:258:5)
在processImmediate[as_immediateCallback](timers.js:330:15)
2) 异步测试失败:
错误:失败
at/private/tmp/so/test/main.js:13:12
在进程中调用(node.js:415:13)

done
传递到it函数做什么?