0.8.2 • Published 9 years ago

rosehip v0.8.2

Weekly downloads
7
License
MIT License
Repository
github
Last release
9 years ago

Rosehip

A simple, no-magic JavaScript unit testing library for browsers and Node.JS.

Because Mocha is very nice, but uses a lot of magic to define tests, making it very compilcated to use in the middle of a pipeline (say, if one wants to compile the tests using CoffeeScript or Babel).

Therefore, Rosehip's unit tests are a regular JavaScript object with a run() function.

rosehip-screenshot

Install

Node.JS or Browserify:

npm install --save-dev rosehip

Browser standalone:

Download rosehip.js (and rosehip.css!) and include it:

<link rel="stylesheet" href="rosehip.css"/>
<script type="application/javascript" src="rosehip.js"></script>

Setup

Node.JS or Browserify:

var rosehip = require('rosehip')
var expect = require('expect.js') // Optional; you can use Node's assert or should.js or anything else

Both Node.JS and standalone:

var test_suite = new rosehip.Test()

Reporters

Output to console.log:

  var reporter = new rosehip.ConsoleReporter(test_suite)

Or, if running in a browser, get a pretty dashboard:

  var element = document.getElementById('test_report')
  var reporter = new rosehip.WebReporter(element, test_suite)

Defining Tests

var test_suite = new rosehip.Test()

// A carrot
var carrot = {
  type: "vegetable",
  color: "yellow", // this carrot is weird
  wind: function(callback){
    var self = this // setTimeout steals 'this'
    setTimeout(function(){
      self.exploded = true
      callback()
    }, 10000)
  } // I knew it. Yellow carrots?
}

test_suite.describe("A carrot", function(test){
  test.it("is a vegetable", function(){
    expect(carrot.type).to.equal("vegetable")
  })

  test.it("is orange", function(){
    expect(carrot.color).to.equal("orange")
  })
  
  test.it("is a root vegetable") // pending test

  test.describe("that explodes", function(test){
    test.it("explodes after 10 seconds", function(done){
      carrot.wind(function(){
        expect(carrot.exploded).to.equal(true)
        done() // if this is not called after 60 seconds, test fails.
      })
    })
  })
})

var reporter = new rosehip.WebReporter(document.getElementById('rosehip_report'), test_suite)
setTimeout(function(){
  test_suite.run()
}, 1000)

Also take a look at these examples:

Running

test_suite.run()
0.8.2

9 years ago

0.8.1

9 years ago

0.8.0

9 years ago

0.7.0

9 years ago

0.6.0

10 years ago

0.5.2

10 years ago

0.5.1

10 years ago

0.5.0

10 years ago

0.4.1

10 years ago

0.4.0

10 years ago

0.3.1

10 years ago

0.3.0

10 years ago

0.2.0

10 years ago

0.1.0

10 years ago