Skip to content

Instantly share code, notes, and snippets.

@repeatingbeats
Created January 27, 2011 20:07
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save repeatingbeats/799136 to your computer and use it in GitHub Desktop.
Save repeatingbeats/799136 to your computer and use it in GitHub Desktop.
Example structure for nodeunit tests with nested groups and setUp/tearDown functions
/**
* Example structure for nodeunit tests with nested groups and setup/teardown
* functions. Run | nodeunit nodeunit_example.js | to see a printout of
* function names in the order that they are called. There aren't any actual
* tests here.
*/
process.env.NODE_ENV = 'test';
var testCase = require('nodeunit').testCase;
exports.groupOne = testCase({
setUp: function groupOneSetup(cb) {
console.log(arguments.callee.name);
cb();
},
tearDown: function groupOneTearDown(cb) {
console.log(arguments.callee.name);
cb();
},
groupOneTestOne: function groupOneTestOne(test) {
console.log(arguments.callee.name);
test.done();
},
groupOneTestTwo: function groupOneTestTwo(test) {
console.log(arguments.callee.name);
test.done();
},
nestedGroup: testCase({
setUp: function groupOneNestedSetup(cb) {
console.log(arguments.callee.name);
cb();
},
tearDown: function groupOneNestedTearDown(cb) {
console.log(arguments.callee.name);
cb();
},
groupOneNestedTestOne: function groupOneNestedTestOne(test) {
console.log(arguments.callee.name);
test.done();
},
groupOneNestedTestTwo: function groupOneNestedTestTwo(test) {
console.log(arguments.callee.name);
test.done();
},
}),
groupOneTestThree: function groupOneTestThree(test) {
console.log(arguments.callee.name);
test.done();
}
});
exports.groupTwo = {
groupTwoTestOne: function groupTwoTestOne(test) {
console.log(arguments.callee.name);
test.done();
},
groupTwoTestTwo: function groupTwoTestTwo(test) {
console.log(arguments.callee.name);
test.done();
}
}
@ionutzp
Copy link

ionutzp commented Apr 3, 2014

@maniankara
Copy link

wow! works like a charm :) keep it up

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