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

supertest

Package Overview
Dependencies
Maintainers
1
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.0.1 to 0.1.0

History.md

54

lib/test.js

@@ -10,2 +10,3 @@

, http = require('http')
, assert = require('assert')
, Request = request.Request;

@@ -74,15 +75,14 @@

// callback
if ('function' == typeof fn) return this.end(fn);
// header field
if ('string' == typeof fn || fn instanceof RegExp) {
this._fields[val] = fn;
fn = arguments[2];
// body
if ('string' == typeof val || val instanceof RegExp) {
// header field
if ('string' == typeof fn || fn instanceof RegExp) {
this._fields[val] = fn;
fn = arguments[2];
} else {
this._body = val;
}
} else {
this._body = val;
}
// callback
if ('function' == typeof fn) this.end(fn);

@@ -106,2 +106,3 @@ return this;

});
return this;
};

@@ -121,2 +122,3 @@

, body = this._body
, isregexp = body instanceof RegExp
, expected

@@ -134,13 +136,27 @@ , actual

// body
if (null != body && body !== res.text) {
var a = util.inspect(body);
var b = util.inspect(res.text);
if (null != body) {
// parsed
if ('object' == typeof body && !isregexp) {
try {
assert.deepEqual(body, res.body);
} catch (err) {
var a = util.inspect(body);
var b = util.inspect(res.body);
return fn(new Error('expected ' + a + ' response body, got ' + b));
}
} else {
// string
if (body !== res.text) {
var a = util.inspect(body);
var b = util.inspect(res.text);
// regexp
if (body instanceof RegExp) {
if (!body.test(res.text)) {
return fn(new Error('expected body ' + b + ' to match ' + body));
// regexp
if (isregexp) {
if (!body.test(res.text)) {
return fn(new Error('expected body ' + b + ' to match ' + body));
}
} else {
return fn(new Error('expected ' + a + ' response body, got ' + b));
}
}
} else {
return fn(new Error('expected ' + a + ' response body, got ' + b));
}

@@ -147,0 +163,0 @@ }

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

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

@@ -66,3 +66,4 @@

Assert response `body` text with a string or regular expression.
Assert response `body` text with a string, regular expression, or
parsed body object.

@@ -69,0 +70,0 @@ ### .expect(field, value[, fn])

@@ -104,2 +104,38 @@

it('should assert the response text', function(done){
var app = express();
app.set('json spaces', 0);
app.get('/', function(req, res){
res.send({ foo: 'bar' });
});
request(app)
.get('/')
.expect('{"foo":"bar"}', done);
})
it('should assert the parsed response body', function(done){
var app = express();
app.set('json spaces', 0);
app.get('/', function(req, res){
res.send({ foo: 'bar' });
});
request(app)
.get('/')
.expect({ foo: 'baz' })
.end(function(err, res){
err.message.should.equal('expected { foo: \'baz\' } response body, got { foo: \'bar\' }');
request(app)
.get('/')
.expect({ foo: 'bar' })
.end(done);
});
})
it('should support regular expressions', function(done){

@@ -106,0 +142,0 @@ var app = express();

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