Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Allow numbers to be used for asserting headers #106

Merged
merged 1 commit into from

2 participants

@swang

Hi. First off thanks for making this module. Makes testing web app routes easy to test.

This change allows a number to be used as the second parameter (value) when asserting headers using expect()

e.g. expect('Content-Length', 20)

I ran into this problem when I was passing string.length for the content length and was getting a confusing error message ([Error: expected 'Content-Length' response body, got 'Z9ASMVNVDM']) because I couldn't understand why supertest was expecting 'Content-Length' in the body.

@swang swang Allow numbers to be used for asserting headers
This change allows a number to be used as the second parameter
(value) when asserting headers using expect()

e.g. expect('Content-Length', 20)
5c2bdba
@gjohnson gjohnson merged commit 3e117d2 into visionmedia:master

1 check passed

Details default The Travis CI build passed
@gjohnson
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 4, 2014
  1. @swang

    Allow numbers to be used for asserting headers

    swang authored
    This change allows a number to be used as the second parameter
    (value) when asserting headers using expect()
    
    e.g. expect('Content-Length', 20)
This page is out of date. Refresh to see the latest.
Showing with 17 additions and 1 deletion.
  1. +1 −1  lib/test.js
  2. +16 −0 test/supertest.js
View
2  lib/test.js
@@ -98,7 +98,7 @@ Test.prototype.expect = function(a, b, c){
}
// 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] = [];
this._fields[a].push(b);
return this;
View
16 test/supertest.js
@@ -400,6 +400,22 @@ describe('request(app)', function(){
});
})
+ 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(){
it('reports errors',function(done) {
var app = express();
Something went wrong with that request. Please try again.