Skip to content
Myr

req.accepts.js

This file

Path

test/req.accepts.js

137 lines · 3.2 KiB · JavaScript

Last changed by

Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption752b5f7

History of this file

Take it

The walk stopped after 200 commits: lines older than 3923ec8 point at it.

remove route-loading exampleTJ Holowaychukbefore adoption3923ec8

lines 1–17why, one step back
1
2var express = require('../')3 , request = require('./support/http');45describe('req', function(){6 describe('.accepts(type)', function(){7 it('should return true when Accept is not present', function(done){8 var app = express();910 app.use(function(req, res, next){11 res.end(req.accepts('json') ? 'yes' : 'no');12 });1314 request(app)15 .get('/')16 .expect('yes', done);17 })

Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoptionc6d7352

line 18why, one step back
18

remove route-loading exampleTJ Holowaychukbefore adoption3923ec8

lines 19–30why, one step back
19 it('should return true when present', function(done){
20 var app = express();2122 app.use(function(req, res, next){23 res.end(req.accepts('json') ? 'yes' : 'no');24 });2526 request(app)27 .get('/')28 .set('Accept', 'application/json')29 .expect('yes', done);30 })

Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoptionc6d7352

line 31why, one step back
31

remove route-loading exampleTJ Holowaychukbefore adoption3923ec8

lines 32–58why, one step back
32 it('should return false otherwise', function(done){
33 var app = express();3435 app.use(function(req, res, next){36 res.end(req.accepts('json') ? 'yes' : 'no');37 });3839 request(app)40 .get('/')41 .set('Accept', 'text/html')42 .expect('no', done);43 })44 })4546 it('should accept a comma-delimited list of types', function(done){47 var app = express();4849 app.use(function(req, res, next){50 res.end(req.accepts('json, html'));51 });5253 request(app)54 .get('/')55 .set('Accept', 'text/html')56 .expect('html', done);57 })58

Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption752b5f7

lines 59–71why, one step back
59 it('should accept an argument list of type names', function(done){
60 var app = express();6162 app.use(function(req, res, next){63 res.end(req.accepts('json', 'html'));64 });6566 request(app)67 .get('/')68 .set('Accept', 'application/json')69 .expect('json', done);70 })71

remove route-loading exampleTJ Holowaychukbefore adoption3923ec8

lines 72–137why, one step back
72 describe('.accept(types)', function(){
73 it('should return the first when Accept is not present', function(done){74 var app = express();7576 app.use(function(req, res, next){77 res.end(req.accepts(['json', 'html']));78 });7980 request(app)81 .get('/')82 .expect('json', done);83 })8485 it('should return the first acceptable type', function(done){86 var app = express();8788 app.use(function(req, res, next){89 res.end(req.accepts(['json', 'html']));90 });9192 request(app)93 .get('/')94 .set('Accept', 'text/html')95 .expect('html', done);96 })9798 it('should return false when no match is made', function(done){99 var app = express();100101 app.use(function(req, res, next){102 res.end(req.accepts(['text/html', 'application/json']) ? 'yup' : 'nope');103 });104105 request(app)106 .get('/')107 .set('Accept', 'foo/bar, bar/baz')108 .expect('nope', done);109 })110111 it('should take quality into account', function(done){112 var app = express();113114 app.use(function(req, res, next){115 res.end(req.accepts(['text/html', 'application/json']));116 });117118 request(app)119 .get('/')120 .set('Accept', '*/html; q=.5, application/json')121 .expect('application/json', done);122 })123124 it('should return the first acceptable type with canonical mime types', function(done){125 var app = express();126127 app.use(function(req, res, next){128 res.end(req.accepts(['application/json', 'text/html']));129 });130131 request(app)132 .get('/')133 .set('Accept', '*/html')134 .expect('text/html', done);135 })136 })137})