Skip to content

Instantly share code, notes, and snippets.

@juhasz
Created March 17, 2015 14:49
Show Gist options
  • Save juhasz/5b8c963e711111d662b1 to your computer and use it in GitHub Desktop.
Save juhasz/5b8c963e711111d662b1 to your computer and use it in GitHub Desktop.
Example for mocha hook hierarchy
'use strict';
var should = require('chai').should();
describe("A", function() {
before(function (done) {
console.log("-- 1 A.before");
done();
});
after(function (done) {
console.log("-- 1 A.after");
done();
});
beforeEach(function(done) {
console.log("-- 3 A.beforeEach");
done();
});
afterEach(function(done) {
console.log("-- 3 A.afterEach");
done();
});
describe("A.1", function() {
before(function (done) {
console.log("-- 2 A.1.before");
done();
});
after(function (done) {
console.log("-- 2 A.1.after");
done();
});
beforeEach(function(done) {
console.log("-- 4 A.1.beforeEach");
done();
});
afterEach(function(done) {
console.log("-- 4 A.1.afterEach");
done();
});
it("A.1.a", function(done) {
console.log("-- 5 A.1.a");
done();
});
it("A.1.b", function(done) {
console.log("-- 5 A.1.b");
done();
});
});
describe("A.2", function() {
before(function (done) {
console.log("-- 2 A.2.before");
done();
});
after(function (done) {
console.log("-- 2 A.2.after");
done();
});
beforeEach(function(done) {
console.log("-- 4 A.2.beforeEach");
done();
});
afterEach(function(done) {
console.log("-- 4 A.2.afterEach");
done();
});
it("A.2.a", function(done) {
console.log("-- 5 A.2.a");
done();
});
it("A.2.b", function(done) {
console.log("-- 5 A.2.b");
done();
});
describe("A.2.1", function() {
before(function (done) {
console.log("-- 2 A.2.1.before");
done();
});
after(function (done) {
console.log("-- 2 A.2.1.after");
done();
});
beforeEach(function(done) {
console.log("-- 5 A.2.1.beforeEach");
done();
});
afterEach(function(done) {
console.log("-- 5 A.2.1.afterEach");
done();
});
it("A.2.1.a", function(done) {
console.log("-- 6 A.2.1.a");
done();
});
it("A.2.1.b", function(done) {
console.log("-- 6 A.2.1.b");
done();
});
});
});
});
mocha mocha-hook-hierarchy.js | grep ^--
# -- 1 A.before
# -- 2 A.1.before
# -- 3 A.beforeEach
# -- 4 A.1.beforeEach
# -- 5 A.1.a
# -- 4 A.1.afterEach
# -- 3 A.afterEach
# -- 3 A.beforeEach
# -- 4 A.1.beforeEach
# -- 5 A.1.b
# -- 4 A.1.afterEach
# -- 3 A.afterEach
# -- 2 A.1.after
# -- 2 A.2.before
# -- 3 A.beforeEach
# -- 4 A.2.beforeEach
# -- 5 A.2.a
# -- 4 A.2.afterEach
# -- 3 A.afterEach
# -- 3 A.beforeEach
# -- 4 A.2.beforeEach
# -- 5 A.2.b
# -- 4 A.2.afterEach
# -- 3 A.afterEach
# -- 2 A.2.1.before
# -- 3 A.beforeEach
# -- 4 A.2.beforeEach
# -- 5 A.2.1.beforeEach
# -- 6 A.2.1.a
# -- 5 A.2.1.afterEach
# -- 4 A.2.afterEach
# -- 3 A.afterEach
# -- 3 A.beforeEach
# -- 4 A.2.beforeEach
# -- 5 A.2.1.beforeEach
# -- 6 A.2.1.b
# -- 5 A.2.1.afterEach
# -- 4 A.2.afterEach
# -- 3 A.afterEach
# -- 2 A.2.1.after
# -- 2 A.2.after
# -- 1 A.after
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment