Getting started

In this tutorial you’ll learn how to write your first tests using jstest
and how to run them in the browser. Let’s start by writing a spec for some
code we want to write, say, an implementation of the Set data structure.
This class must be able to store a unique collection of strings and tell us
whether a string is in the set or not.

Let’s start by creating a few directories to hold our project (this mirrors
the structure of the jstest GitHub repo
if you want to download the finished example). Download jstest and save it
into the build/ directory, and create the following directories:

build/
jstest.js
example/
browser.html
lib/
set.js
spec/
set_spec.js

Writing a spec

We’ll write a spec for our project in spec/set_spec.js. A spec begins with
a call to JS.Test.describe(), with the tests nested inside.

Setting up a test page

We’ve written a simple spec for one method in our class, now we need a way to
run it. To do this, make a page in browser.html containing the following
code. All it does it load jstest, our code, and our tests, and tell
JS.Test to run the test suite: