Fork me on GitHub

JSpec JavaScript Testing Framework

JSpec is a extremely small, yet very powerful testing framework. Utilizing its own custom grammar and pre-processor, JSpec can operate in ways that no other JavaScript testing framework can. This includes many helpful shorthand literals, a very intuitive / readable syntax, as well as not polluting core object prototypes.

JSpec can also be run in a variety of ways, such as via the terminal with Rhino support, via browsers using the DOM or Console formatters, or finally by using the Ruby JavaScript testing framework which runs browsers in the background, reporting back to the terminal.

Features

Example

describe 'ShoppingCart' var cart before_each cart = new ShoppingCart end describe 'addProducts' it 'should add several products' cart.addProduct('cookie') cart.addProduct('icecream') cart.should.have 2, 'products' end end describe 'checkout' it 'throw an error when checking out with no products' -{ cart.clear().checkout() }.should.throw_error end end end

DOM Formatter

The DOM formatter is the default of JSpec, featuring assertion graphs and a sleek white style.

JSpec DOM Formatter

Matchers

Click a matcher below to view an example

Core

  • be
  • eql
  • equal
  • be_a
  • be_an
  • be_an_instance_of
  • be_at_least
  • be_at_most
  • be_within
  • be_null
  • be_empty
  • be_true
  • be_false
  • be_type
  • be_greater_than
  • be_less_than
  • have
  • have_at_least
  • have_at_most
  • have_within
  • have_length
  • have_prop
  • have_property
  • include
  • match
  • throw_error
  • respond_to

jQuery

  • have_tag
  • have_one
  • have_tags
  • have_many
  • have_child
  • have_children
  • have_text
  • have_attr
  • have_value
  • have_class
  • have_classes
  • be_visible
  • be_hidden
  • be_enabled
  • be_disabled
  • be_selected
  • be_checked
  • have_type
  • have_id
  • have_title
  • have_alt
  • have_href
  • have_src
  • have_rel
  • have_rev
  • have_name
  • have_target

JSpec Executable

The packaged JSpec executable allows you to quickly initialize project templates which utilize JSpec, update them with the lateast versions of JSpec, as well as auto-run suites in multiple browsers when a file is altered. For information beyond the examples below consult `jspec help`.

# Initialize template in the current directory 
$ jspec init

# Initialize using Rhino template at ./myproject
$ jspec init myproject --rhino

# Initialize using the JSpec server
$ jspec init --server
# Update to the lateast version of JSpec within your spec suite
$ jspec update

# Update a specific file
$ jspec update spec/run-suites.html
# Refresh suites when any JavaScript is altered
$ jspec

# Run suites once
$ jspec run

# Refresh suites when altered in a custom suite path, and several browsers
$ jspec spec/run-suites.html --browsers Safari,Firefox

More Information

Authors

TJ Holowaychuk (tj@vision-media.ca)