n. Gerbils: Inquisitive, friendly animals that rarely bite, TDD for the rest of us
Gerbil attemps to be an uber simple and minimalistic testing framework for javascript. It's written in coffeescript so be nice with me
$ npm install gerbil
You can now execute the tests with node without to depend on the browser
var scenario = require('gerbil');
scenario("Testing with node", {
"should work in a terminal": function(){
assert(true);
}
});
scenario("This is my scenario", {
"setup": function(){
// When scenario starts
window.some_class = new MagicClass;
},
"before": function(){
// Before every test
some_class.magic_magic();
},
"after": function(){
// After every test
some_class.clean();
},
"cleanup": function(){
// When the scenario ends
window.some_class = false;
},
"MagicClass should have a length": function(){
some_class.add(1);
assert_equal(some_class.length, 1);
},
"MagicClass should be valid": function (){
assert(some_class.valid);
}
});
var my_cool_logger = {
"warn": function(msg){},
"log": function(msg){},
"error": function(msg){
alert(msg);
},
};
scenario("Fancy scenario", {
"somewhere over the rainbow": function(){
assert(false);
}
}, my_cool_logger);
// Change global logger
GerbilOptions.logger = my_cool_logger;
scenario("Fancy scenario is back", {
"somewhere over the double rainbow": function(){
assert(false);
}
});
The results are only shown in the console, the one from console.log Run it with an open inspector or define a custom logger
And in the bottom you will find the summary
- Workaround for tests using setTimeout
- Trigger events on tests
- Get a gerbil as a pet