Global `before` and `beforeEach` for mocha? Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Global `before` and `beforeEach` for mocha? without wasting too much if your time.

The question is published on by Tutorial Guruji team.

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 same.

How do I provide a global before and beforeEach for all of them (or some of them)?

Answer

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'
We are here to answer your question about Global `before` and `beforeEach` for mocha? - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji