tests: fix up primitive tests for res.jsonp
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 519126d · Browse files · 1 file·+46 added−57 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+46 added−57 removed
- tests:+46 added−57 removed
Provenance
- Commit
1b2f3a0- Tree
ed08939- Author
Douglas Christopher Wilson <doug@somethingdoug.com>- Committer
Douglas Christopher Wilson <doug@somethingdoug.com>- Parent
519126d
1 file changed+46 added−57 removed
modified:test/res.jsonp.js+46 added-57 removed
154 unmodified lines155 .expect('X-Content-Type-Options', 'nosniff')156 .expect(200, /cb\(\{"hello":"world"\}\);$/, done);157 })158 159- describe('when given primitives', function(){160- it('should respond with json', function(done){161- var app = express();159+ describe('when given null', function () {160+ it('should invoke callback with null', function (done) {161+ var app = express()162 163- app.use(function(req, res){164- res.jsonp(null);165- });163+ app.use(function (req, res) {164+ res.jsonp(null)165+ })166 167 request(app)168- .get('/')169- .expect('Content-Type', 'application/json; charset=utf-8')170- .expect(200, 'null', done)168+ .get('/?callback=cb')169+ .expect('Content-Type', 'text/javascript; charset=utf-8')170+ .expect(200, /cb\(null\)/, done)171 })172 })173 174- describe('when given an array', function(){175- it('should respond with json', function(done){176- var app = express();174+ describe('when given a string', function () {175+ it('should invoke callback with a string', function (done) {176+ var app = express()177 178- app.use(function(req, res){179- res.jsonp(['foo', 'bar', 'baz']);180- });178+ app.use(function (req, res) {179+ res.jsonp('tobi')180+ })181 182 request(app)183- .get('/')184- .expect('Content-Type', 'application/json; charset=utf-8')185- .expect(200, '["foo","bar","baz"]', done)183+ .get('/?callback=cb')184+ .expect('Content-Type', 'text/javascript; charset=utf-8')185+ .expect(200, /cb\("tobi"\)/, done)186 })187 })188 189- describe('when given an object', function(){190- it('should respond with json', function(done){191- var app = express();189+ describe('when given a number', function () {190+ it('should invoke callback with a number', function (done) {191+ var app = express()192 193- app.use(function(req, res){194- res.jsonp({ name: 'tobi' });195- });193+ app.use(function (req, res) {194+ res.jsonp(42)195+ })196 197 request(app)198- .get('/')199- .expect('Content-Type', 'application/json; charset=utf-8')200- .expect(200, '{"name":"tobi"}', done)198+ .get('/?callback=cb')199+ .expect('Content-Type', 'text/javascript; charset=utf-8')200+ .expect(200, /cb\(42\)/, done)201 })202 })203 204- describe('when given primitives', function(){205- it('should respond with json for null', function(done){206- var app = express();204+ describe('when given an array', function () {205+ it('should invoke callback with an array', function (done) {206+ var app = express()207 208- app.use(function(req, res){209- res.jsonp(null);210- });208+ app.use(function (req, res) {209+ res.jsonp(['foo', 'bar', 'baz'])210+ })211 212 request(app)213- .get('/')214- .expect('Content-Type', 'application/json; charset=utf-8')215- .expect(200, 'null', done)213+ .get('/?callback=cb')214+ .expect('Content-Type', 'text/javascript; charset=utf-8')215+ .expect(200, /cb\(\["foo","bar","baz"\]\)/, done)216 })217+ })218 219+ describe('when given an object', function () {218- it('should respond with json for Number', function(done){219- var app = express();220+ it('should invoke callback with an object', function (done) {221+ var app = express()222 221- app.use(function(req, res){222- res.jsonp(300);223- });223+ app.use(function (req, res) {224+ res.jsonp({ name: 'tobi' })225+ })226 227 request(app)226- .get('/')227- .expect('Content-Type', 'application/json; charset=utf-8')228- .expect(200, '300', done)228+ .get('/?callback=cb')229+ .expect('Content-Type', 'text/javascript; charset=utf-8')230+ .expect(200, /cb\(\{"name":"tobi"\}\)/, done)231 })230-231- it('should respond with json for String', function(done){232- var app = express();233-234- app.use(function(req, res){235- res.jsonp('str');236- });237-238- request(app)239- .get('/')240- .expect('Content-Type', 'application/json; charset=utf-8')241- .expect(200, '"str"', done)242- })232 })233 234 describe('"json escape" setting', function () {235 it('should be undefined by default', function () {121 unmodified lines