简体   繁体   中英

can we write before & after block to a particular test case (it) of mocha

Can I write something write below? Can I declare before method to a particular test case like we use to do in describe block.

describe('demo test suite', function(){
 it('demo test case one', function(){.....})
 it('demo test case two', function(done){
   before(function(){
     //Do some operation only for this particular test case
   })
   //Do some operation again    
 })
})

Your intentions are little bit unclear to me, but you can nest describe functions:

describe('demo test suite', function(){
 it('demo test case one', function(){.....})
 describe('demo test case two', function(done){
   before(function(){
     //Do some operation
   })
   it('....', function(){
     //Do some operation again
   })     
 })
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM