Main principles
Tests must start with a clean state
Tests must be runnable in isolation
Stub most performance heavy operation
Naming convention
// Given this object
function Class () {
this . args = nopt ();
};
Class . exclude = function () {};
Class . name = 'Yeoman' ;
Class . prototype . find = function () {};
// We'd have this test structure
describe ( 'Class' , function () {
describe ( '.exclude()' , function () {});
describe ( '.name' , function () {});
describe ( '#find()' , function () {});
describe ( '#args' , function () {});
});
// BAD
it ( 'should find generators' );
// GOOD
it ( 'find generators' );
Assertion
// BAD
assert ( Generator . appname , 'Generator has an `appname` property' );
// GOOD
assert ( Generator . appname , 'Expected Generator to have an `appname` property' );
Stylistic preferences
.bind()
throwing assertions
// BAD
assert . throws ( function () {
class . method ( 'Invalid param' );
});
// GOOD
assert . throws ( class . method . bind ( class , 'Invalid param' ));