Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devkhan/247639286790bacdf2de089ce7a09a97 to your computer and use it in GitHub Desktop.
Save devkhan/247639286790bacdf2de089ce7a09a97 to your computer and use it in GitHub Desktop.
Show the order of execution of mocha's before and beforeEach hooks for each describe and each test
describe('highest level describe', function () {
before(function() {
console.log('This is the highest level before')
})
beforeEach(function() {
console.log('This is the highest level beforeEach')
})
it('This is the first highest level test', function() {
console.log('first highest level test')
true;
})
it('This is the second highest level test', function() {
console.log('second highest level test')
true;
})
describe('nested describe', function() {
before(function() {
console.log('This is the nested before')
})
beforeEach(function() {
console.log('This is the nested beforeEach')
})
it('This is the first nested test', function() {
console.log('first nested test')
true;
})
it('This is the second nested test', function() {
console.log('second nested test')
true;
})
describe('a nested\'s nested', function() {
before(function() {
console.log('This is the nested\'s nested before')
})
beforeEach(function() {
console.log('This is the nested\'s nested beforeEach')
})
it('This is the first nested\'s nested test', function() {
console.log('first nested\'s nested test')
true;
})
it('This is the second nested\'s nested test', function() {
console.log('second nested\'s nested test')
true;
})
})
})
})
highest level describe
This is the highest level before
This is the highest level beforeEach
first highest level test
√ This is the first highest level test
This is the highest level beforeEach
second highest level test
√ This is the second highest level test
nested describe
This is the nested before
This is the highest level beforeEach
This is the nested beforeEach
first nested test
√ This is the first nested test
This is the highest level beforeEach
This is the nested beforeEach
second nested test
√ This is the second nested test
a nested's nested
This is the nested's nested before
This is the highest level beforeEach
This is the nested beforeEach
This is the nested's nested beforeEach
first nested's nested test
√ This is the first nested's nested test
This is the highest level beforeEach
This is the nested beforeEach
This is the nested's nested beforeEach
second nested's nested test
√ This is the second nested's nested test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment