Activate your free membership today | Log-in

Thursday, November 5th, 2009

Riot.js: JavaScript port of the lean fast unit test framework

Category: JavaScript, Testing

<>p>Riot started as a lean Ruby unit test framework with tests that have a style like this:

RUBY:
    context "a new user" do
      setup { User.new }
      asserts("that it is not yet created") { topic.new_record? }
    end

Alex Young has now implemented Riot.js which brings you the lean framework in a format that can run stand-along via Rhino, or through the browser itself with tests that look like:

JAVASCRIPT:
  1.  
  2. Riot.run(function() {
  3.   context('basic riot functionality', function() {
  4.     given('some simple equality tests', function() {
  5.       asserts('a simple truth test should return true', true).isTrue();
  6.       asserts('isNull is null', null).isNull();
  7.     });
  8.  
  9.     given('another context', function() {
  10.       asserts('equals should compare strings as expected', 'test string').equals('test string');
  11.     });
  12.  
  13.     given('a context concerned with functions', function() {
  14.       asserts('asserts() should allow functions to be compared', function() {
  15.         return 'test string';
  16.       }).equals('test string');
  17.     });
  18.   });
  19.  
  20.   given('yet another context', function() {
  21.     asserts('equals should compare strings as expected', 'test string').equals('test string');
  22.   });
  23. });
  24.  

Related Content:

Posted by Dion Almaer at 6:12 am
2 Comments

+----
1.5 rating from 60 votes

2 Comments »

Comments feed TrackBack URI

^ Hilarious spam post wuwei. Failed attempt in boosting Google search ranking.

I might give Riot a try, in need of a real simple Unit Tester for js.

Comment by davidck — November 9, 2009

Leave a comment

You must be logged in to post a comment.