Skip to content

Latest commit

 

History

History
104 lines (79 loc) · 2.15 KB

README.md

File metadata and controls

104 lines (79 loc) · 2.15 KB

Gerbil

Gerbil!

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

Now with npm

$ 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);
  }
});

Console Errors

Example

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);
  }
});

Custom logger

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);
  }
});

What's the catch?

The results are only shown in the console, the one from console.log Run it with an open inspector or define a custom logger

Console tests

And in the bottom you will find the summary

Console summary

TODO

  1. Workaround for tests using setTimeout
  2. Trigger events on tests
  3. Get a gerbil as a pet