Skip to content

Instantly share code, notes, and snippets.

@corywheeler
Created December 12, 2014 17:14
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save corywheeler/73dd40d89d417758fb2e to your computer and use it in GitHub Desktop.
Save corywheeler/73dd40d89d417758fb2e 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