Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
JavaScript unit tests.
JavaScript
tree: b6368cfd49

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
.gitignore
README.textile
riot.js
riotjs.html
test.js

README.textile

This is a JavaScript implementation of Riot

It will run in a browser or in Rhino.

The tests look like this:

Riot.run(function() {
  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

Assertions

  • equals – for example, asserts('description').equals('value')
  • matches – matches a regex
  • typeOf – aliased to isTypeOf, kindOf
  • isNull
  • isTrue
  • raises

Riot.run

Riot.run(function() { // your tests }); just adds your tests to window.onload. If there’s already an onload handler it’ll prepend it. If there’s no window it will just run the tests.

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

Todo

  • Extract the assertions into their own property list so adding user-defined ones is cleaner
  • Package as rubygem (-xpcc)
Something went wrong with that request. Please try again.