-
-
Save armujahid/027a29ea3593d737a8830b0823f74c0d to your computer and use it in GitHub Desktop.
Mocha before() & beforeEach() execution order with nested describe()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
describe('mocha before hooks', function () { | |
before(() => console.log('*** top-level before()')); | |
beforeEach(() => console.log('*** top-level beforeEach()')); | |
describe('nesting', function () { | |
before(() => console.log('*** nested before()')); | |
beforeEach(() => console.log('*** nested beforeEach()')); | |
it('is a nested spec', () => true); | |
it('is a 2nd nested spec', () => true); | |
}); | |
}); | |
// mocha before hooks | |
// *** top-level before() | |
// nesting | |
// *** nested before() | |
// *** top-level beforeEach() | |
// *** nested beforeEach() | |
// ✓ is a nested spec | |
// *** top-level beforeEach() | |
// *** nested beforeEach() | |
// ✓ is a 2nd nested spec | |
// | |
// | |
// 1 passing (8ms) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment