Simple full-stack HTTP testing for express applications
CoffeeScript
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
src
test
.gitignore
.npmignore
.travis.yml
README.md
package.json

README.md

springboard

Build Status

Installing

npm install springboard

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

npm install
npm test

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