Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gpittarelli/123fcf7864a41b4117850469a6153dbb to your computer and use it in GitHub Desktop.
Save gpittarelli/123fcf7864a41b4117850469a6153dbb to your computer and use it in GitHub Desktop.
Mocha hooks ordering
describe("Level 1", () => {
before(() => console.log("before 1"));
beforeEach(() => console.log("beforeEach 1"));
before(() => console.log("before 2"));
beforeEach(() => console.log("beforeEach 2"));
after(() => console.log("after 1"));
afterEach(() => console.log("afterEach 1"));
after(() => console.log("after 2"));
afterEach(() => console.log("afterEach 2"));
describe("Level 2", () => {
before(() => console.log("before 3"));
beforeEach(() => console.log("beforeEach 3"));
before(() => console.log("before 4"));
beforeEach(() => console.log("beforeEach 4"));
after(() => console.log("after 3"));
afterEach(() => console.log("afterEach 3"));
after(() => console.log("after 4"));
afterEach(() => console.log("afterEach 4"));
it("Test", () => {});
});
});
Level 1
before 1
before 2
Level 2
before 3
before 4
beforeEach 1
beforeEach 2
beforeEach 3
beforeEach 4
✓ Test
afterEach 3
afterEach 4
afterEach 1
afterEach 2
after 3
after 4
after 1
after 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment