tests: add more res.jsonp? tests

This commit is contained in:
Douglas Christopher Wilson 2014-05-08 21:27:01 -04:00
parent 35a66d8a14
commit 920f46ad65
2 changed files with 87 additions and 1 deletions

View File

@ -18,7 +18,7 @@ describe('res', function(){
})
describe('when given primitives', function(){
it('should respond with json', function(done){
it('should respond with json for null', function(done){
var app = express();
app.use(function(req, res){
@ -33,6 +33,40 @@ describe('res', function(){
done();
})
})
it('should respond with json for Number', function(done){
var app = express();
app.use(function(req, res){
res.json(300);
});
request(app)
.get('/')
.end(function(err, res){
res.statusCode.should.equal(200);
res.headers.should.have.property('content-type', 'application/json; charset=utf-8');
res.text.should.equal('300');
done();
})
})
it('should respond with json for String', function(done){
var app = express();
app.use(function(req, res){
res.json('str');
});
request(app)
.get('/')
.end(function(err, res){
res.statusCode.should.equal(200);
res.headers.should.have.property('content-type', 'application/json; charset=utf-8');
res.text.should.equal('"str"');
done();
})
})
})
describe('when given an array', function(){

View File

@ -173,6 +173,58 @@ describe('res', function(){
})
})
describe('when given primitives', function(){
it('should respond with json for null', function(done){
var app = express();
app.use(function(req, res){
res.jsonp(null);
});
request(app)
.get('/')
.end(function(err, res){
res.headers.should.have.property('content-type', 'application/json; charset=utf-8');
res.text.should.equal('null');
done();
})
})
it('should respond with json for Number', function(done){
var app = express();
app.use(function(req, res){
res.jsonp(300);
});
request(app)
.get('/')
.end(function(err, res){
res.statusCode.should.equal(200);
res.headers.should.have.property('content-type', 'application/json; charset=utf-8');
res.text.should.equal('300');
done();
})
})
it('should respond with json for String', function(done){
var app = express();
app.use(function(req, res){
res.jsonp('str');
});
request(app)
.get('/')
.end(function(err, res){
res.statusCode.should.equal(200);
res.headers.should.have.property('content-type', 'application/json; charset=utf-8');
res.text.should.equal('"str"');
done();
})
})
})
describe('"json replacer" setting', function(){
it('should be passed to JSON.stringify()', function(done){
var app = express();