tests: remove more mocking uses
This commit is contained in:
parent
b95f2ee820
commit
855176b633
@ -37,7 +37,7 @@ describe('req', function(){
|
||||
var app = express();
|
||||
|
||||
app.use(function(req, res){
|
||||
res._headers = undefined;
|
||||
res._headers = null;
|
||||
res.send(req.fresh);
|
||||
});
|
||||
|
||||
|
@ -37,7 +37,7 @@ describe('req', function(){
|
||||
var app = express();
|
||||
|
||||
app.use(function(req, res){
|
||||
res._headers = undefined;
|
||||
res._headers = null;
|
||||
res.send(req.stale);
|
||||
});
|
||||
|
||||
|
@ -81,7 +81,7 @@ describe('res', function(){
|
||||
it('should be invoked instead of auto-responding', function(done){
|
||||
request(app3)
|
||||
.get('/')
|
||||
.set('Accept: text/html')
|
||||
.set('Accept', 'text/html')
|
||||
.expect('default', done);
|
||||
})
|
||||
})
|
||||
|
@ -1,14 +1,20 @@
|
||||
|
||||
var express = require('../')
|
||||
, res = express.response;
|
||||
var express = require('..');
|
||||
var request = require('supertest');
|
||||
|
||||
describe('res', function(){
|
||||
describe('.get(field)', function(){
|
||||
it('should get the response header field', function(){
|
||||
res.setHeader('Content-Type', 'text/x-foo');
|
||||
res.get('Content-Type').should.equal('text/x-foo');
|
||||
res.get('Content-type').should.equal('text/x-foo');
|
||||
res.get('content-type').should.equal('text/x-foo');
|
||||
it('should get the response header field', function (done) {
|
||||
var app = express();
|
||||
|
||||
app.use(function (req, res) {
|
||||
res.setHeader('Content-Type', 'text/x-foo');
|
||||
res.send(res.get('Content-Type'));
|
||||
});
|
||||
|
||||
request(app)
|
||||
.get('/')
|
||||
.expect(200, 'text/x-foo', done);
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -1,41 +1,46 @@
|
||||
|
||||
var express = require('../')
|
||||
, res = express.response;
|
||||
var express = require('..');
|
||||
var request = require('supertest');
|
||||
|
||||
describe('res', function(){
|
||||
|
||||
beforeEach(function() {
|
||||
res.removeHeader('link');
|
||||
});
|
||||
|
||||
describe('.links(obj)', function(){
|
||||
it('should set Link header field', function(){
|
||||
res.links({
|
||||
next: 'http://api.example.com/users?page=2',
|
||||
last: 'http://api.example.com/users?page=5'
|
||||
it('should set Link header field', function (done) {
|
||||
var app = express();
|
||||
|
||||
app.use(function (req, res) {
|
||||
res.links({
|
||||
next: 'http://api.example.com/users?page=2',
|
||||
last: 'http://api.example.com/users?page=5'
|
||||
});
|
||||
res.end();
|
||||
});
|
||||
|
||||
res.get('link')
|
||||
.should.equal(
|
||||
'<http://api.example.com/users?page=2>; rel="next", '
|
||||
+ '<http://api.example.com/users?page=5>; rel="last"');
|
||||
request(app)
|
||||
.get('/')
|
||||
.expect('Link', '<http://api.example.com/users?page=2>; rel="next", <http://api.example.com/users?page=5>; rel="last"')
|
||||
.expect(200, done);
|
||||
})
|
||||
|
||||
it('should set Link header field for multiple calls', function() {
|
||||
res.links({
|
||||
next: 'http://api.example.com/users?page=2',
|
||||
last: 'http://api.example.com/users?page=5'
|
||||
it('should set Link header field for multiple calls', function (done) {
|
||||
var app = express();
|
||||
|
||||
app.use(function (req, res) {
|
||||
res.links({
|
||||
next: 'http://api.example.com/users?page=2',
|
||||
last: 'http://api.example.com/users?page=5'
|
||||
});
|
||||
|
||||
res.links({
|
||||
prev: 'http://api.example.com/users?page=1'
|
||||
});
|
||||
|
||||
res.end();
|
||||
});
|
||||
|
||||
res.links({
|
||||
prev: 'http://api.example.com/users?page=1',
|
||||
});
|
||||
|
||||
res.get('link')
|
||||
.should.equal(
|
||||
'<http://api.example.com/users?page=2>; rel="next", '
|
||||
+ '<http://api.example.com/users?page=5>; rel="last", '
|
||||
+ '<http://api.example.com/users?page=1>; rel="prev"');
|
||||
request(app)
|
||||
.get('/')
|
||||
.expect('Link', '<http://api.example.com/users?page=2>; rel="next", <http://api.example.com/users?page=5>; rel="last", <http://api.example.com/users?page=1>; rel="prev"')
|
||||
.expect(200, done);
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -1,7 +1,6 @@
|
||||
|
||||
var express = require('../')
|
||||
, request = require('supertest')
|
||||
, res = express.response;
|
||||
var express = require('..');
|
||||
var request = require('supertest');
|
||||
|
||||
describe('res', function(){
|
||||
describe('.set(field, value)', function(){
|
||||
@ -18,10 +17,18 @@ describe('res', function(){
|
||||
.end(done);
|
||||
})
|
||||
|
||||
it('should coerce to a string', function(){
|
||||
res.headers = {};
|
||||
res.set('X-Number', 123);
|
||||
res.get('X-Number').should.equal('123');
|
||||
it('should coerce to a string', function (done) {
|
||||
var app = express();
|
||||
|
||||
app.use(function (req, res) {
|
||||
res.set('X-Number', 123);
|
||||
res.end(typeof res.get('X-Number'));
|
||||
});
|
||||
|
||||
request(app)
|
||||
.get('/')
|
||||
.expect('X-Number', '123')
|
||||
.expect(200, 'string', done);
|
||||
})
|
||||
})
|
||||
|
||||
@ -39,11 +46,18 @@ describe('res', function(){
|
||||
.expect('["type=ninja","language=javascript"]', done);
|
||||
})
|
||||
|
||||
it('should coerce to an array of strings', function(){
|
||||
res.headers = {};
|
||||
res.set('X-Numbers', [123, 456]);
|
||||
JSON.stringify(res.get('X-Numbers'))
|
||||
.should.equal('["123","456"]');
|
||||
it('should coerce to an array of strings', function (done) {
|
||||
var app = express();
|
||||
|
||||
app.use(function (req, res) {
|
||||
res.set('X-Numbers', [123, 456]);
|
||||
res.end(JSON.stringify(res.get('X-Numbers')));
|
||||
});
|
||||
|
||||
request(app)
|
||||
.get('/')
|
||||
.expect('X-Numbers', '123, 456')
|
||||
.expect(200, '["123","456"]', done);
|
||||
})
|
||||
})
|
||||
|
||||
@ -65,10 +79,18 @@ describe('res', function(){
|
||||
.end(done);
|
||||
})
|
||||
|
||||
it('should coerce to a string', function(){
|
||||
res.headers = {};
|
||||
res.set({ 'X-Number': 123 });
|
||||
res.get('X-Number').should.equal('123');
|
||||
it('should coerce to a string', function (done) {
|
||||
var app = express();
|
||||
|
||||
app.use(function (req, res) {
|
||||
res.set({ 'X-Number': 123 });
|
||||
res.end(typeof res.get('X-Number'));
|
||||
});
|
||||
|
||||
request(app)
|
||||
.get('/')
|
||||
.expect('X-Number', '123')
|
||||
.expect(200, 'string', done);
|
||||
})
|
||||
})
|
||||
})
|
||||
|
105
test/res.vary.js
105
test/res.vary.js
@ -1,55 +1,96 @@
|
||||
|
||||
var express = require('../')
|
||||
, should = require('should');
|
||||
|
||||
function response() {
|
||||
var res = Object.create(express.response);
|
||||
res._headers = {};
|
||||
return res;
|
||||
}
|
||||
var assert = require('assert');
|
||||
var express = require('..');
|
||||
var request = require('supertest');
|
||||
|
||||
describe('res.vary()', function(){
|
||||
describe('with no arguments', function(){
|
||||
it('should not set Vary', function(){
|
||||
var res = response();
|
||||
res.vary();
|
||||
should.not.exist(res.get('Vary'));
|
||||
it('should not set Vary', function (done) {
|
||||
var app = express();
|
||||
|
||||
app.use(function (req, res) {
|
||||
res.vary();
|
||||
res.end();
|
||||
});
|
||||
|
||||
request(app)
|
||||
.get('/')
|
||||
.expect(shouldNotHaveHeader('Vary'))
|
||||
.expect(200, done);
|
||||
})
|
||||
})
|
||||
|
||||
describe('with an empty array', function(){
|
||||
it('should not set Vary', function(){
|
||||
var res = response();
|
||||
res.vary([]);
|
||||
should.not.exist(res.get('Vary'));
|
||||
it('should not set Vary', function (done) {
|
||||
var app = express();
|
||||
|
||||
app.use(function (req, res) {
|
||||
res.vary([]);
|
||||
res.end();
|
||||
});
|
||||
|
||||
request(app)
|
||||
.get('/')
|
||||
.expect(shouldNotHaveHeader('Vary'))
|
||||
.expect(200, done);
|
||||
})
|
||||
})
|
||||
|
||||
describe('with an array', function(){
|
||||
it('should set the values', function(){
|
||||
var res = response();
|
||||
res.vary(['Accept', 'Accept-Language', 'Accept-Encoding']);
|
||||
res.get('Vary').should.equal('Accept, Accept-Language, Accept-Encoding');
|
||||
it('should set the values', function (done) {
|
||||
var app = express();
|
||||
|
||||
app.use(function (req, res) {
|
||||
res.vary(['Accept', 'Accept-Language', 'Accept-Encoding']);
|
||||
res.end();
|
||||
});
|
||||
|
||||
request(app)
|
||||
.get('/')
|
||||
.expect('Vary', 'Accept, Accept-Language, Accept-Encoding')
|
||||
.expect(200, done);
|
||||
})
|
||||
})
|
||||
|
||||
describe('with a string', function(){
|
||||
it('should set the value', function(){
|
||||
var res = response();
|
||||
res.vary('Accept');
|
||||
res.get('Vary').should.equal('Accept');
|
||||
it('should set the value', function (done) {
|
||||
var app = express();
|
||||
|
||||
app.use(function (req, res) {
|
||||
res.vary('Accept');
|
||||
res.end();
|
||||
});
|
||||
|
||||
request(app)
|
||||
.get('/')
|
||||
.expect('Vary', 'Accept')
|
||||
.expect(200, done);
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the value is present', function(){
|
||||
it('should not add it again', function(){
|
||||
var res = response();
|
||||
res.vary('Accept');
|
||||
res.vary('Accept-Encoding');
|
||||
res.vary('Accept-Encoding');
|
||||
res.vary('Accept-Encoding');
|
||||
res.vary('Accept');
|
||||
res.get('Vary').should.equal('Accept, Accept-Encoding');
|
||||
it('should not add it again', function (done) {
|
||||
var app = express();
|
||||
|
||||
app.use(function (req, res) {
|
||||
res.vary('Accept');
|
||||
res.vary('Accept-Encoding');
|
||||
res.vary('Accept-Encoding');
|
||||
res.vary('Accept-Encoding');
|
||||
res.vary('Accept');
|
||||
res.end();
|
||||
});
|
||||
|
||||
request(app)
|
||||
.get('/')
|
||||
.expect('Vary', 'Accept, Accept-Encoding')
|
||||
.expect(200, done);
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
function shouldNotHaveHeader(header) {
|
||||
return function (res) {
|
||||
assert.ok(!(header.toLowerCase() in res.headers), 'should not have header ' + header);
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user