2013-05-25 11 views

答えて

12

はい、テストが失敗した場合は、afterafterEachフックの両方を実行する必要があります。 #94#125#143#690

は、関連する議論や変更のためにこれらのgithubの問題を参照してください。ここで

は、私の主張を証明する例です。

モカ1.1.12で次の出力を生成し
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'); 
    }); 
    }); 
}); 

․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) 
関連する問題