req.accepts.js
This file
Path
test/req.accepts.js
45 lines · 1.0 KiB · JavaScript
Last changed by
mergedTj Holowaychukbefore adoption547d18c
History of this fileTake it
12345678910111213141516171819202122232425262728293031323334353637383940414243444546
var express = require('../') , request = require('./support/http');
describe('req', function(){ describe('.accepts(type)', function(){ it('should return true when Accept is not present', function(done){ var app = express();
app.use(function(req, res, next){ res.end(req.accepts('json') ? 'yes' : 'no'); });
request(app) .get('/') .expect('yes', done); }) it('should return true when present', function(done){ var app = express();
app.use(function(req, res, next){ res.end(req.accepts('json') ? 'yes' : 'no'); });
request(app) .get('/') .set('Accept', 'application/json') .expect('yes', done); }) it('should return false otherwise', function(done){ var app = express();
app.use(function(req, res, next){ res.end(req.accepts('json') ? 'yes' : 'no'); });
request(app) .get('/') .set('Accept', 'text/html') .expect('no', done); }) })})