Skip to content
Myr

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

7 files+159 added−85 removed

modified:test/req.fresh.js+1 added-1 removed
modified:test/req.stale.js+1 added-1 removed
modified:test/res.format.js+1 added-1 removed
79 unmodified lines
80 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 lines
modified:test/res.get.js+13 added-7 removed
modified:test/res.links.js+32 added-27 removed
modified:test/res.set.js+38 added-16 removed
12var express = require('../')3 , request = require('supertest')4 , res = express.response;2var express = require('..');3var request = require('supertest');45describe('res', function(){6 describe('.set(field, value)', function(){7 it('should set the response header field', function(done){
8 unmodified lines
16 .expect('Content-Type', 'text/x-foo')17 .end(done);18 })1921 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();2223 app.use(function (req, res) {24 res.set('X-Number', 123);25 res.end(typeof res.get('X-Number'));26 });2728 request(app)29 .get('/')30 .expect('X-Number', '123')31 .expect(200, 'string', done);32 })33 })3435 describe('.set(field, values)', function(){
9 unmodified lines
45 .get('/')46 .expect('["type=ninja","language=javascript"]', done);47 })4842 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();5152 app.use(function (req, res) {53 res.set('X-Numbers', [123, 456]);54 res.end(JSON.stringify(res.get('X-Numbers')));55 });5657 request(app)58 .get('/')59 .expect('X-Numbers', '123, 456')60 .expect(200, '["123","456"]', done);61 })62 })6364 describe('.set(object)', function(){
13 unmodified lines
78 .expect('X-Bar', 'baz')79 .end(done);80 })8168 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();8485 app.use(function (req, res) {86 res.set({ 'X-Number': 123 });87 res.end(typeof res.get('X-Number'));88 });8990 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
12var express = require('../')3 , should = require('should');2var assert = require('assert');3var express = require('..');4var request = require('supertest');55function response() {6 var res = Object.create(express.response);7 res._headers = {};8 return res;9}106describe('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();1011 app.use(function (req, res) {12 res.vary();13 res.end();14 });1516 request(app)17 .get('/')18 .expect(shouldNotHaveHeader('Vary'))19 .expect(200, done);20 })21 })2223 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();2627 app.use(function (req, res) {28 res.vary([]);29 res.end();30 });3132 request(app)33 .get('/')34 .expect(shouldNotHaveHeader('Vary'))35 .expect(200, done);36 })37 })3839 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();4243 app.use(function (req, res) {44 res.vary(['Accept', 'Accept-Language', 'Accept-Encoding']);45 res.end();46 });4748 request(app)49 .get('/')50 .expect('Vary', 'Accept, Accept-Language, Accept-Encoding')51 .expect(200, done);52 })53 })5455 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();5859 app.use(function (req, res) {60 res.vary('Accept');61 res.end();62 });6364 request(app)65 .get('/')66 .expect('Vary', 'Accept')67 .expect(200, done);68 })69 })7071 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();7475 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 });8384 request(app)85 .get('/')86 .expect('Vary', 'Accept, Accept-Encoding')87 .expect(200, done);88 })89 })90})9192function shouldNotHaveHeader(header) {93 return function (res) {94 assert.ok(!(header.toLowerCase() in res.headers), 'should not have header ' + header);95 };96}