From e4302b21208c90ae86949933063ccfc1c9fd5c54 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Thu, 8 May 2014 23:22:18 -0400 Subject: [PATCH] tests: fixup new json tests --- test/res.json.js | 32 ++++++++++++++------------------ test/res.jsonp.js | 46 ++++++++++++++++++++++++++++------------------ 2 files changed, 42 insertions(+), 36 deletions(-) diff --git a/test/res.json.js b/test/res.json.js index c088ab45..97eea7eb 100644 --- a/test/res.json.js +++ b/test/res.json.js @@ -17,6 +17,20 @@ describe('res', function(){ .expect('{"foo":"bar"}', done); }) + it('should not override previous Content-Types', function(done){ + var app = express(); + + app.get('/', function(req, res){ + res.type('application/vnd.example+json'); + res.json({ hello: 'world' }); + }); + + request(app) + .get('/') + .expect('Content-Type', 'application/vnd.example+json') + .expect(200, '{"hello":"world"}', done); + }) + describe('when given primitives', function(){ it('should respond with json', function(done){ var app = express(); @@ -156,22 +170,4 @@ describe('res', function(){ }) }) }) - - it('should not override previous Content-Types', function(done){ - var app = express(); - - app.get('/', function(req, res){ - res.type('application/vnd.example+json'); - res.json({ hello: 'world' }); - }); - - request(app) - .get('/') - .end(function(err, res){ - res.statusCode.should.equal(200); - res.headers.should.have.property('content-type', 'application/vnd.example+json'); - res.text.should.equal('{"hello":"world"}'); - done(); - }) - }) }) diff --git a/test/res.jsonp.js b/test/res.jsonp.js index 46381cf7..1b8db297 100644 --- a/test/res.jsonp.js +++ b/test/res.jsonp.js @@ -119,6 +119,34 @@ describe('res', function(){ }); }); + it('should not override previous Content-Types with no callback', function(done){ + var app = express(); + + app.get('/', function(req, res){ + res.type('application/vnd.example+json'); + res.jsonp({ hello: 'world' }); + }); + + request(app) + .get('/') + .expect('Content-Type', 'application/vnd.example+json') + .expect(200, '{"hello":"world"}', done); + }) + + it('should override previous Content-Types with callback', function(done){ + var app = express(); + + app.get('/', function(req, res){ + res.type('application/vnd.example+json'); + res.jsonp({ hello: 'world' }); + }); + + request(app) + .get('/?callback=cb') + .expect('Content-Type', 'text/javascript; charset=utf-8') + .expect(200, /cb\(\{"hello":"world"\}\);$/, done); + }) + describe('when given primitives', function(){ it('should respond with json', function(done){ var app = express(); @@ -258,22 +286,4 @@ describe('res', function(){ }) }) }) - - it('should not override previous Content-Types', function(done){ - var app = express(); - - app.get('/', function(req, res){ - res.type('application/vnd.example+json'); - res.jsonp({ hello: 'world' }); - }); - - request(app) - .get('/') - .end(function(err, res){ - res.statusCode.should.equal(200); - res.headers.should.have.property('content-type', 'application/vnd.example+json'); - res.text.should.equal('{"hello":"world"}'); - done(); - }) - }) })