Javascript testing framework inspired by Python's doctest
Pull request Compare This branch is 89 commits behind ianb:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.resources
esprima @ f3ee094
examples
.gitignore
.gitmodules
.hgignore
.syncignore
README.md
doctest.css
doctest.js
index.html
index_template.html
package.json

README.md

doctest.js

For a more complete description please read the main page.

doctest.js is a test runner for Javascript, inspired by Python's doctest.

The tests are embedded in an HTML page, and look like what Javascript might look like if you are using an interactive prompt. An example of a test (note $ is uesd as a prompt, > as a continuation prompt):

$ // You can do really simple tests...
$ print(3 * 4);
12
$ // Or more complicated tests...
$ var complete = false;
$ var savedResult = null;
$ $.ajax({ // don't get confused by the two uses of $ here
>   url: "/test",
>   dataType: "json",
>   success: function (result) {
>     complete = true;
>     savedResult = result;
>   }
> });
$ wait(function () {return complete;});
$ print(savedResult);
{value1: "something", value2: true}

Also included is a simple mock object. An example of using it:

$ $.ajax({
>   url: "/test",
>   dataType: "json",
>   success: Spy('success', {wait: true})
> });
success({value1: "something", value2: true})

You can also write the Javascript with comments to show the expected output:

function factorial(n) {
  return n == 1 ? 1 : n * factorial(n-1);
}
print(factorial(3))
/* => 6 */

For more and better (and live) examples see the doctest.js website.