Rodrigo
Rodrigo

Reputation: 391

beforeAll/beforeEach afterAll/afterEach should be inside `describe`?

I am bit confused. Should beforeAll/beforeEach/afterAll/afterEach be inside describe or outside?

Example:

describe('unamed', () => {
  beforeAll(async () => {
     //
  })
})

Vs

beforeAll(async () => {
  //
})

describe('unamed', () => {
  //
})

Which is correct? Or doesn't matter?

Upvotes: 3

Views: 1566

Answers (1)

Mureinik
Mureinik

Reputation: 312066

If you have a before/after function at the top level of the file, it will apply to all the tests in the file. If you have them inside a describe scope, they only apply to the tests under that describe scope.

Upvotes: 4

Related Questions