Global `before` and `beforeEach` for mocha?

后端 未结 5 976
长情又很酷
长情又很酷 2021-02-01 00:38

I\'m using mocha for javascript unit-testing now.

I have several test files, each file has a before and beforeEach, but they are exactly the s

5条回答
  •  独厮守ぢ
    2021-02-01 00:54

    Declare a before or beforeEach in a separate file (I use spec_helper.coffee) and require it.

    spec_helper.coffee

    afterEach (done) ->
      async.parallel [
        (cb) -> Listing.remove {}, cb
        (cb) -> Server.remove {}, cb
      ], ->
        done()
    

    test_something.coffee

    require './spec_helper'
    

提交回复
热议问题