springboard

Full stack HTTP testing for Express

npm install springboard
2 downloads in the last week
4 downloads in the last month

springboard

Build Status

Usage

springboard makes it simple to write full-stack HTTP tests for your express applications. Let's start with a simple express application.

express = require "express"
app = express()

app.use express.bodyParser()
app.use express.methodOverride()
app.use app.router

app.get "/hello", (req, res) ->
  res.send "Hello, world!"

app.post "/post", (req, res) ->
  res.send "Hello, #{req.body.name}!"

module.exports = app

Now, let's write some tests with springboard! We'll use the mocha testing framework and chai for assertions.

expect = require("chai").expect
springboard = require "springboard"
app = require "./app.coffee"

describe "springboard", ->
  it "handles GET requests", (done) ->
    springboard.withServer app, (r) ->
      r.get "/hello", (err, result) ->
        expect(result).to.eql("Hello, world!")
        r.stop()
        done()

  it "allows POST requests with form data", (done) ->
    springboard.withServer app, (r) ->
      r.post "/post", {name: "Drew"}, (err, result, response) ->
        expect(result).to.eql("Hello, Drew!")
        r.stop()
        done()

  it "allows POST requests with JSON data", (done) ->
    springboard.withServer app, (r) ->
      r.post "/post", JSON.stringify({name: "Drew"}), (err, result, response) ->
        expect(result).to.eql("Hello, Drew!")
        r.stop()
        done()

For more examples, take a look at the tests.

Contributing

To install dependencies, compile the coffeescript and run the tests, just run

rake

Now write some tests, make them pass and send me a pull request!

npm loves you