摩卡beforeEach在一套房正在运行另一套房

我有两个testing套件(我使用摩卡的TDD UI,它使用suite() ,test()而不是describe()it() ):

 suite('first suite'), function(){ .... }) suite('second suite', function(){ beforeEach(function(done){ console.log('I SHOULD NOT BE RUN') this.timeout(5 * 1000); deleteTestAccount(ordering, function(err){ done(err) }) }) ... }() 

运行mocha -g 'first suite只运行mocha -g 'first suitetesting,但运行beforeEach,打印I SHOULD NOT BE RUN在控制台上I SHOULD NOT BE RUN

我怎样才能使beforeEach()只运行在它所包含的套件?

注意 :我可以解决这个问题:

 beforeEach(function(done){ this.timeout(5 * 1000); if ( this.currentTest.fullTitle().includes('second suite') ) { deleteTestAccount(ordering, function(err){ done(err) }) } else { done(null) } }) 

问题是beforeEach不是TDD UI的一部分,而是BDD UI。 TDD UI的相应function已setup 。 所以请尝试更换beforeEachsetup ,一切都应该如你beforeEach :)。