jShoulda

Shoulda for JavaScript

jShoulda acts as a wrapper to the JsUnitTest library, allowing you to write JavaScript unit tests in a Shoulda-like language.

What you write

context('A test', {
  setup: function() {
    this.foo = 1;
  }
  },
  should('run its setup functions', function() {
    this.assertEqual(1, this.foo);
  }),
  context('which is a "nested" test', {
    setup: function() {
      this.foo += 1;
    }
    },
    should('run both setup functions', function() {
      this.assertEqual(2, this.foo);
    })
  )
)();

… is what you test

2 tests, 2 assertions, 0 failures, 0 errors, 0 warnings
Status Test Message
A test should run its setup functions passed 1 assertions, 0 failures, 0 errors, 0 warnings
A test which is a “nested” test should run both setup functions passed 1 assertions, 0 failures, 0 errors, 0 warnings

Download jShoulda

Note: in March, 2009, the author abandoned work in jShoulda in favor of SugarTest, a new library wich uses an improved and richer syntax (and still works on top of JsUnitTest).

Interested? Check our tutorial on jShoulda.

jShoulda has been created by Choan Galvez and is freely distributable under the terms of a MIT-style license. The source code resides in a Git repository at github.