3 var express = require('../')
4 , request = require('supertest');
6 describe('req', function(){
7 describe('.accepts(type)', function(){
8 it('should return true when Accept is not present', function(done){
11 app.use(function(req, res, next){
12 res.end(req.accepts('json') ? 'yes' : 'no');
20 it('should return true when present', function(done){
23 app.use(function(req, res, next){
24 res.end(req.accepts('json') ? 'yes' : 'no');
29 .set('Accept', 'application/json')
33 it('should return false otherwise', function(done){
36 app.use(function(req, res, next){
37 res.end(req.accepts('json') ? 'yes' : 'no');
42 .set('Accept', 'text/html')
47 it('should accept an argument list of type names', function(done){
50 app.use(function(req, res, next){
51 res.end(req.accepts('json', 'html'));
56 .set('Accept', 'application/json')
57 .expect('json', done);
60 describe('.accepts(types)', function(){
61 it('should return the first when Accept is not present', function(done){
64 app.use(function(req, res, next){
65 res.end(req.accepts(['json', 'html']));
70 .expect('json', done);
73 it('should return the first acceptable type', function(done){
76 app.use(function(req, res, next){
77 res.end(req.accepts(['json', 'html']));
82 .set('Accept', 'text/html')
83 .expect('html', done);
86 it('should return false when no match is made', function(done){
89 app.use(function(req, res, next){
90 res.end(req.accepts(['text/html', 'application/json']) ? 'yup' : 'nope');
95 .set('Accept', 'foo/bar, bar/baz')
96 .expect('nope', done);
99 it('should take quality into account', function(done){
102 app.use(function(req, res, next){
103 res.end(req.accepts(['text/html', 'application/json']));
108 .set('Accept', '*/html; q=.5, application/json')
109 .expect('application/json', done);
112 it('should return the first acceptable type with canonical mime types', function(done){
115 app.use(function(req, res, next){
116 res.end(req.accepts(['application/json', 'text/html']));
121 .set('Accept', '*/html')
122 .expect('text/html', done);