Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

supertest

Package Overview
Dependencies
Maintainers
2
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

supertest - npm Package Compare versions

Comparing version 0.9.2 to 0.10.0

6

History.md

@@ -0,1 +1,7 @@

0.10.0 / 2014-03-20
==================
* assert respond body prior to the status code
* add documentation for .agent()
0.9.2 / 2014-03-17

@@ -2,0 +8,0 @@ ==================

16

lib/test.js

@@ -101,3 +101,3 @@

// header field
if ('string' == typeof b || b instanceof RegExp) {
if ('string' == typeof b || 'number' == typeof b || b instanceof RegExp) {
if (!this._fields[a]) this._fields[a] = [];

@@ -148,9 +148,2 @@ this._fields[a].push(b);

// status
if (status && res.status !== status) {
var a = http.STATUS_CODES[status];
var b = http.STATUS_CODES[res.status];
return fn(new Error('expected ' + status + ' "' + a + '", got ' + res.status + ' "' + b + '"'), res);
}
// body

@@ -202,2 +195,9 @@ for (var i = 0; i < bodies.length; i++) {

// status
if (status && res.status !== status) {
var a = http.STATUS_CODES[status];
var b = http.STATUS_CODES[res.status];
return fn(new Error('expected ' + status + ' "' + a + '", got ' + res.status + ' "' + b + '"'), res);
}
// asserts

@@ -204,0 +204,0 @@ for (var i = 0; i < this._asserts.length; i++) {

{
"name": "supertest",
"version": "0.9.2",
"version": "0.10.0",
"description": "Super-agent driven library for testing HTTP servers",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -96,3 +96,46 @@ # SuperTest

```
Here's an example with mocha that shows how to persist a request and its cookies:
```js
var request = require('supertest')
, should = require('should')
, express = require('express');
var app = express();
app.use(express.cookieParser());
describe('request.agent(app)', function(){
var app = express();
app.use(express.cookieParser());
app.get('/', function(req, res){
res.cookie('cookie', 'hey');
res.send();
});
app.get('/return', function(req, res){
if (req.cookies.cookie) res.send(req.cookies.cookie);
else res.send(':(')
});
var agent = request.agent(app);
it('should save cookies', function(done){
agent
.get('/')
.expect('set-cookie', 'cookie=hey; Path=/', done);
})
it('should send cookies', function(done){
agent
.get('/return')
.expect('hey', done);
})
})
```
There is another example that is introduced by the file [agency.js](https://github.com/visionmedia/superagent/blob/master/test/node/agency.js)
## API

@@ -99,0 +142,0 @@

@@ -255,2 +255,21 @@

it('should assert the body before the status', function (done) {
var app = express();
app.set('json spaces', 0);
app.get('/', function(req, res){
res.send(500, { message: 'something went wrong' });
});
request(app)
.get('/')
.expect(200)
.expect('hey')
.end(function(err, res){
err.message.should.equal('expected \'hey\' response body, got \'{"message":"something went wrong"}\'');
done();
});
});
it('should assert the response text', function(done){

@@ -404,2 +423,18 @@ var app = express();

it('should support numbers', function(done){
var app = express();
app.get('/', function(req, res){
res.send('hey');
});
request(app)
.get('/')
.expect('Content-Length', 4)
.end(function(err){
err.message.should.equal('expected "Content-Length" of "4", got "3"');
done();
});
})
describe('handling arbitrary expect functions', function(){

@@ -604,1 +639,2 @@ it('reports errors',function(done) {

})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc