Skip to content

Instantly share code, notes, and snippets.

@brettz9
Forked from harto/before.js
Created September 28, 2018 13:58
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 brettz9/edf19498980b4e134d02ed2608fae571 to your computer and use it in GitHub Desktop.
Save brettz9/edf19498980b4e134d02ed2608fae571 to your computer and use it in GitHub Desktop.
Mocha before() & beforeEach() execution order with nested describe()
'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);
});
});
// mocha before hooks
// *** top-level before()
// nesting
// *** nested before()
// *** top-level beforeEach()
// *** nested beforeEach()
// ✓ is a nested spec
//
//
// 1 passing (8ms)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment