tests: remove more mocking uses
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Douglas Christopher Wilson · committed by Douglas Christopher Wilson · parent b95f2ee · Browse files · 7 files·+159 added−85 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
7 files+159 added−85 removed
- tests:+159 added−85 removed
Provenance
- Commit
855176b- Tree
dda2716- Author
Douglas Christopher Wilson <doug@somethingdoug.com>- Committer
Douglas Christopher Wilson <doug@somethingdoug.com>- Parent
b95f2ee
7 files changed+159 added−85 removed
modified:test/req.fresh.js+1 added-1 removed
35 unmodified lines363738394040414243445 unmodified lines35 unmodified lines it('should return false without response headers', function(done){ var app = express();
app.use(function(req, res){ res._headers = undefined; res._headers = null; res.send(req.fresh); });
request(app)5 unmodified linesmodified:test/req.stale.js+1 added-1 removed
35 unmodified lines363738394040414243445 unmodified lines35 unmodified lines it('should return true without response headers', function(done){ var app = express();
app.use(function(req, res){ res._headers = undefined; res._headers = null; res.send(req.stale); });
request(app)5 unmodified linesmodified:test/res.format.js+1 added-1 removed
79 unmodified lines80 describe('given .default', function(){81 it('should be invoked instead of auto-responding', function(done){82 request(app3)83 .get('/')84- .set('Accept: text/html')84+ .set('Accept', 'text/html')85 .expect('default', done);86 })87 })88 71 unmodified linesmodified:test/res.get.js+13 added-7 removed
1232345678910117891011121314151617181920
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); }) })})modified:test/res.links.js+32 added-27 removed
12323456789106789121314151011121314151617181920211819202122232425262728242526272829303132303133343536373839343536373840414243444546
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 (done) { var app = express();
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' 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.links({ prev: 'http://api.example.com/users?page=1' });
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", ' + '<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); }) })})modified:test/res.set.js+38 added-16 removed
1 2-var express = require('../')3- , request = require('supertest')4- , res = express.response;2+var express = require('..');3+var request = require('supertest');4 5 describe('res', function(){6 describe('.set(field, value)', function(){7 it('should set the response header field', function(done){8 unmodified lines16 .expect('Content-Type', 'text/x-foo')17 .end(done);18 })19 21- it('should coerce to a string', function(){22- res.headers = {};23- res.set('X-Number', 123);24- res.get('X-Number').should.equal('123');20+ it('should coerce to a string', function (done) {21+ var app = express();22+23+ app.use(function (req, res) {24+ res.set('X-Number', 123);25+ res.end(typeof res.get('X-Number'));26+ });27+28+ request(app)29+ .get('/')30+ .expect('X-Number', '123')31+ .expect(200, 'string', done);32 })33 })34 35 describe('.set(field, values)', function(){9 unmodified lines45 .get('/')46 .expect('["type=ninja","language=javascript"]', done);47 })48 42- it('should coerce to an array of strings', function(){43- res.headers = {};44- res.set('X-Numbers', [123, 456]);45- JSON.stringify(res.get('X-Numbers'))46- .should.equal('["123","456"]');49+ it('should coerce to an array of strings', function (done) {50+ var app = express();51+52+ app.use(function (req, res) {53+ res.set('X-Numbers', [123, 456]);54+ res.end(JSON.stringify(res.get('X-Numbers')));55+ });56+57+ request(app)58+ .get('/')59+ .expect('X-Numbers', '123, 456')60+ .expect(200, '["123","456"]', done);61 })62 })63 64 describe('.set(object)', function(){13 unmodified lines78 .expect('X-Bar', 'baz')79 .end(done);80 })81 68- it('should coerce to a string', function(){69- res.headers = {};70- res.set({ 'X-Number': 123 });71- res.get('X-Number').should.equal('123');82+ it('should coerce to a string', function (done) {83+ var app = express();84+85+ app.use(function (req, res) {86+ res.set({ 'X-Number': 123 });87+ res.end(typeof res.get('X-Number'));88+ });89+90+ request(app)91+ .get('/')92+ .expect('X-Number', '123')93+ .expect(200, 'string', done);94 })95 })96 })modified:test/res.vary.js+73 added-32 removed
1 2-var express = require('../')3- , should = require('should');2+var assert = require('assert');3+var express = require('..');4+var request = require('supertest');5 5-function response() {6- var res = Object.create(express.response);7- res._headers = {};8- return res;9-}10-6 describe('res.vary()', function(){7 describe('with no arguments', function(){13- it('should not set Vary', function(){14- var res = response();15- res.vary();16- should.not.exist(res.get('Vary'));8+ it('should not set Vary', function (done) {9+ var app = express();10+11+ app.use(function (req, res) {12+ res.vary();13+ res.end();14+ });15+16+ request(app)17+ .get('/')18+ .expect(shouldNotHaveHeader('Vary'))19+ .expect(200, done);20 })21 })22 23 describe('with an empty array', function(){21- it('should not set Vary', function(){22- var res = response();23- res.vary([]);24- should.not.exist(res.get('Vary'));24+ it('should not set Vary', function (done) {25+ var app = express();26+27+ app.use(function (req, res) {28+ res.vary([]);29+ res.end();30+ });31+32+ request(app)33+ .get('/')34+ .expect(shouldNotHaveHeader('Vary'))35+ .expect(200, done);36 })37 })38 39 describe('with an array', function(){29- it('should set the values', function(){30- var res = response();31- res.vary(['Accept', 'Accept-Language', 'Accept-Encoding']);32- res.get('Vary').should.equal('Accept, Accept-Language, Accept-Encoding');40+ it('should set the values', function (done) {41+ var app = express();42+43+ app.use(function (req, res) {44+ res.vary(['Accept', 'Accept-Language', 'Accept-Encoding']);45+ res.end();46+ });47+48+ request(app)49+ .get('/')50+ .expect('Vary', 'Accept, Accept-Language, Accept-Encoding')51+ .expect(200, done);52 })53 })54 55 describe('with a string', function(){37- it('should set the value', function(){38- var res = response();39- res.vary('Accept');40- res.get('Vary').should.equal('Accept');56+ it('should set the value', function (done) {57+ var app = express();58+59+ app.use(function (req, res) {60+ res.vary('Accept');61+ res.end();62+ });63+64+ request(app)65+ .get('/')66+ .expect('Vary', 'Accept')67+ .expect(200, done);68 })69 })70 71 describe('when the value is present', function(){45- it('should not add it again', function(){46- var res = response();47- res.vary('Accept');48- res.vary('Accept-Encoding');49- res.vary('Accept-Encoding');50- res.vary('Accept-Encoding');51- res.vary('Accept');52- res.get('Vary').should.equal('Accept, Accept-Encoding');72+ it('should not add it again', function (done) {73+ var app = express();74+75+ app.use(function (req, res) {76+ res.vary('Accept');77+ res.vary('Accept-Encoding');78+ res.vary('Accept-Encoding');79+ res.vary('Accept-Encoding');80+ res.vary('Accept');81+ res.end();82+ });83+84+ request(app)85+ .get('/')86+ .expect('Vary', 'Accept, Accept-Encoding')87+ .expect(200, done);88 })89 })90 })91+92+function shouldNotHaveHeader(header) {93+ return function (res) {94+ assert.ok(!(header.toLowerCase() in res.headers), 'should not have header ' + header);95+ };96+}