No commit activity in last 3 years
JavaScript unit tests.
 Project Readme

This is a JavaScript implementation of Riot.

It will run in a browser, Rhino, or Node.


Tests look like this: {
  context('basic riot functionality', function() {
    given('some simple equality tests', function() {
      asserts('a simple truth test should return true', true).isTrue();
      asserts('isNull is null', null).isNull();

    given('another context', function() {
      asserts('equals should compare strings as expected', 'test string').equals('test string');

    given('a context concerned with functions', function() {
      asserts('asserts() should allow functions to be compared', function() {
        return 'test string';
      }).equals('test string');

  given('yet another context', function() {
    asserts('equals should compare strings as expected', 'test string').equals('test string');

There are a few aliases to make tests (and output) read more naturally:

  • context: given — Given will add “Given…” to the title in the test output
  • asserts: should


  • equals – for example, asserts('description').equals('value')
  • matches – matches a regex
  • typeOf – aliased to isTypeOf, kindOf
  • isNull
  • isTrue
  • raises { // your tests }); just adds your tests to window.onload. If there’s already an onload handler it won’t add itself. If there’s no window it will just run the tests.

Riot.load() can be used to load required scripts in a browser or interpreter. Riot.require() only loads files once by keeping a record of files that have already been loaded.

It can also be called with no parameters to run tests defined with Riot.context. This can be used to create a set of files with tests inside a Riot.context for each file


Packaged as a RubyGem usable via XPCOMCore-RubyGemsriotjs-xpcc.

Writing a test for a browser AND interpreter

My current pattern looks like this:

var Riot;
if (typeof load !== 'undefined') {
} else if (typeof require !== 'undefined') {
  Riot = require('./riot').Riot;


Riot.context('turing.oo.js', function() {
  // Tests go here
<!DOCTYPE html>
p.pass { color: green; font-weight: bold; margin: 0 } { color: red; font-weight: bold; margin: 0 }
#test-results ul { margin-bottom: 1em }
    <script type="text/javascript" src="riot.js"></script>
    <script type="text/javascript" src="core_test.js"></script>
    <script type="text/javascript" src="oo_test.js"></script>
    <div id="test-results"></div>


  • load() is no-op’d in browsers if it doesn’t exist by Riot
  • will only run once, so you can include multiple Riot test files
  • Specifying at the end of each test file lets you run that file with js in the console


  • ac94 (Aron Carroll)
  • bgerrissen (Ben Gerrissen)