I can't seem to get the following integration test to pass in an express project using mocha, supertest, and should (and coffeescript).
should = require('should')
request = require('supertest')
app = require('../../app')
describe 'authentication', ->
describe 'POST /sessions', ->
describe 'success', (done) ->
it 'displays a flash', (done) ->
request(app)
.post('/sessions')
.type('form')
.field('user', 'username')
.field('password', 'password')
.end (err, res) ->
res.text.should.include('logged in')
done()
app.post '/sessions', (req, res) ->
req.flash 'info', "You are now logged in as #{req.body.user}"
res.redirect '/login'
1) authentication POST /sessions success displays a flash:
AssertionError: expected 'Moved Temporarily. Redirecting to //127.0.0.1:3456/login' to include 'logged in'
res.text.should.include('logged in')
expect
.type('form')
.send(user: 'username', password: 'password')
.field()
Moved Temporarily. Redirecting to //127.0.0.1:3456/login
Moved Temporarily. Redirecting to ...
var express = require('express')
var app = express();
module.exports = app;
For anyone who comes across this page, the answer to this question is pretty simple. The Moved Temporarily.
response body is what is returned from supertest. See the issue for more details.
To summarize, I ended up doing something like this.
should = require('should')
request = require('supertest')
app = require('../../app')
describe 'authentication', ->
describe 'POST /sessions', ->
describe 'success', ->
it 'redirects to the right path', (done) ->
request(app)
.post('/sessions')
.send(user: 'username', password: 'password')
.end (err, res) ->
res.header['location'].should.include('/home')
done()
Just check that the response header location
is what you expect it to be. Testing for flash messages and view specific integration tests should be done using another method.