Created
April 3, 2015 21:27
-
-
Save JohnTigue/eb3589db641b0622126a to your computer and use it in GitHub Desktop.
Simple test of mocha's before* and after* hooks with some nesting. No async.
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'; | |
/** Drive this via mocha. Simple 101 explorations of the hooks in mocha. | |
*/ | |
var expect = require('chai').expect; | |
/** So, just how complicated do the hooks get? | |
* https://medium.com/@kanyang/hooks-in-mocha-87cb43baa91c | |
* | |
* Ha, after writing this code, found almost identical stuff on stackoverflow: | |
* http://stackoverflow.com/questions/21418580/what-is-the-difference-between-before-and-beforeeach | |
*/ | |
describe('moch-explorations.js', function(){ | |
before(function(){console.log('beforeA')}); | |
beforeEach(function(){console.log('beforeEachA');}); | |
it('should be happy to be aliveA.1',function(){ | |
console.log('itA.1'); | |
expect(true); | |
}); | |
it('should be happy to be aliveA.2',function(){ | |
console.log('itA.2'); | |
expect(true); | |
}); | |
describe('describeB', function(){ | |
before(function(){console.log('beforeB')}); | |
beforeEach(function(){console.log('beforeEachB');}); | |
it('should be happier to be alive',function(){ | |
console.log('itB'); | |
expect(true); | |
}); | |
afterEach(function(){console.log('afterEachB');}); | |
after(function(){console.log('afterB');}); | |
}); | |
it('should be happy to be aliveA.3',function(){ | |
// This will happen before itB | |
console.log('itA.3'); | |
expect(true); | |
}); | |
afterEach(function(){console.log('afterEveryA');}); | |
after(function(){console.log('afterA');}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I folded this into nodeio, my sandbox for node and io experiments.
https://github.com/JohnTigue/nodeio/blob/master/src/explorations/mocha/before-and-after-basics-no-async.js