Skip to content

Instantly share code, notes, and snippets.

@JohnTigue
Created April 3, 2015 21:27
Show Gist options
  • Save JohnTigue/eb3589db641b0622126a to your computer and use it in GitHub Desktop.
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.
'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');});
});
@JohnTigue
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment