tests: add more res.jsonp? tests
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 35a66d8 · Browse files · 2 files·+87 added−1 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+87 added−1 removed
- tests:+87 added−1 removed
Provenance
- Commit
920f46a- Tree
402c9e1- Author
Douglas Christopher Wilson <doug@somethingdoug.com>- Committer
Douglas Christopher Wilson <doug@somethingdoug.com>- Parent
35a66d8
2 files changed+87 added−1 removed
modified:test/res.json.js+35 added-1 removed
16 unmodified lines17 .expect('{"foo":"bar"}', done);18 })19 20 describe('when given primitives', function(){21- it('should respond with json', function(done){21+ it('should respond with json for null', function(done){22 var app = express();23 24 app.use(function(req, res){25 res.json(null);6 unmodified lines32 res.text.should.equal('null');33 done();34 })35 })36+37+ it('should respond with json for Number', function(done){38+ var app = express();39+40+ app.use(function(req, res){41+ res.json(300);42+ });43+44+ request(app)45+ .get('/')46+ .end(function(err, res){47+ res.statusCode.should.equal(200);48+ res.headers.should.have.property('content-type', 'application/json; charset=utf-8');49+ res.text.should.equal('300');50+ done();51+ })52+ })53+54+ it('should respond with json for String', function(done){55+ var app = express();56+57+ app.use(function(req, res){58+ res.json('str');59+ });60+61+ request(app)62+ .get('/')63+ .end(function(err, res){64+ res.statusCode.should.equal(200);65+ res.headers.should.have.property('content-type', 'application/json; charset=utf-8');66+ res.text.should.equal('"str"');67+ done();68+ })69+ })70 })71 72 describe('when given an array', function(){73 it('should respond with json', function(done){162 unmodified linesmodified:test/res.jsonp.js+52 added
171 unmodified lines172 })173 })174 })175 176+ describe('when given primitives', function(){177+ it('should respond with json for null', function(done){178+ var app = express();179+180+ app.use(function(req, res){181+ res.jsonp(null);182+ });183+184+ request(app)185+ .get('/')186+ .end(function(err, res){187+ res.headers.should.have.property('content-type', 'application/json; charset=utf-8');188+ res.text.should.equal('null');189+ done();190+ })191+ })192+193+ it('should respond with json for Number', function(done){194+ var app = express();195+196+ app.use(function(req, res){197+ res.jsonp(300);198+ });199+200+ request(app)201+ .get('/')202+ .end(function(err, res){203+ res.statusCode.should.equal(200);204+ res.headers.should.have.property('content-type', 'application/json; charset=utf-8');205+ res.text.should.equal('300');206+ done();207+ })208+ })209+210+ it('should respond with json for String', function(done){211+ var app = express();212+213+ app.use(function(req, res){214+ res.jsonp('str');215+ });216+217+ request(app)218+ .get('/')219+ .end(function(err, res){220+ res.statusCode.should.equal(200);221+ res.headers.should.have.property('content-type', 'application/json; charset=utf-8');222+ res.text.should.equal('"str"');223+ done();224+ })225+ })226+ })227+228 describe('"json replacer" setting', function(){229 it('should be passed to JSON.stringify()', function(done){230 var app = express();231 106 unmodified lines