Last active
August 3, 2016 16:53
-
-
Save Sinewyk/30b2fad775f89a8b101144534b362df2 to your computer and use it in GitHub Desktop.
Mocha hooks
This file contains 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
const log = (scope, item) => () => console.log(`${item} of ${scope}`); | |
const dummy = () => {}; | |
describe('Outer scope', function() { | |
before(log(this.title, 'before')); | |
beforeEach(log(this.title, 'beforeEach')); | |
afterEach(log(this.title, 'afterEach')); | |
after(log(this.title, 'after')); | |
it(`#1 in ${this.title}`, dummy); | |
describe('Inner scope', function() { | |
before(log(this.title, 'before')); | |
beforeEach(log(this.title, 'beforeEach')); | |
afterEach(log(this.title, 'afterEach')); | |
after(log(this.title, 'after')); | |
it(`#2 in ${this.title}`, dummy); | |
it(`#3 in ${this.title}`, dummy); | |
}); | |
it(`#4 in ${this.title}`, dummy); | |
}); | |
/* | |
Results in | |
A: | |
Outer scope | |
before of Outer scope | |
beforeEach of Outer scope | |
✓ #1 in Outer scope | |
afterEach of Outer scope | |
beforeEach of Outer scope | |
✓ #4 in Outer scope | |
afterEach of Outer scope | |
beforeEach of Outer scope | |
Inner scope | |
before of Inner scope | |
beforeEach of Inner scope | |
✓ #2 in Inner scope | |
afterEach of Inner scope | |
beforeEach of Inner scope | |
✓ #3 in Inner scope | |
afterEach of Inner scope | |
after of Inner scope | |
afterEach of Outer scope | |
after of Outer scope | |
OR | |
B: | |
Outer scope | |
before of Outer scope | |
beforeEach of Outer scope | |
✓ #1 in Outer scope | |
afterEach of Outer scope | |
beforeEach of Outer scope | |
✓ #4 in Outer scope | |
afterEach of Outer scope | |
Inner scope | |
before of Inner scope | |
beforeEach of Outer scope | |
beforeEach of Inner scope | |
✓ #2 in Inner scope | |
afterEach of Inner scope | |
afterEach of Outer scope | |
beforeEach of Outer scope | |
beforeEach of Inner scope | |
✓ #3 in Inner scope | |
afterEach of Inner scope | |
afterEach of Outer scope | |
after of Inner scope | |
after of Outer scope | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment