supertest-chai

Super-agent driven library for testing HTTP servers with Chai asserts

supertest-chai

HTTP assertions made easy via super-agent and chai

Addresses problem with persisting cookies between requests (issues: https://github.com/visionmedia/supertest/issues/26 and https://github.com/visionmedia/supertest/issues/46).

var supertestChai = require('supertest-chai');
var request = supertestChai.request;
var chai = require("chai");
chai.should();
chai.use(supertestChai.httpAsserts);
 
var express = require('express');
 
var app = express();
 
app.get('/user', function (reqres) {
    res.send(201, { name: 'tobi' });
});
 
app.get('/questions', function (reqres) {
    res.send(200, 'test');
});
 
request(app)
    .get('/user')
    .end(function (res) {
             res.should.be.json;
             res.should.have.status(201);
             res.should.have.header('Content-Length', '15');
             res.body.should.deep.equal({name: 'tobi'});
         });
 
// Access to superagent's agent, making requests using 'user' persists cookies ascross them 
var user = request(app).agent();
 
user
    .get('/questions')
    .end(function (res) {
             res.should.be.html;
             res.should.have.status(200);
             res.should.have.header('Content-Length', '4');
             res.text.should.equal('test');
         });

Inspired by supertest and chai-http

MIT