Skip to content
Myr

app.options.js

This file

Path

test/app.options.js

79 lines · 1.8 KiB · JavaScript

Last changed by

tests: add test for OPTIONS in app.allDouglas Christopher Wilsonbefore adoption0ebfc6b

History of this file

Take it

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

Merge pull request #1877 from reqshark/masterTJ Holowaychukbefore adoptiondc5932d

lines 1–2why, one step back
1
2var express = require('../')

remove unnecessary test/support/httpJonathan Ongbefore adoption643397e

line 3why, one step back
3 , request = require('supertest');

Merge pull request #1877 from reqshark/masterTJ Holowaychukbefore adoptiondc5932d

lines 4–17why, one step back
4
5describe('OPTIONS', function(){6 it('should default to the routes defined', function(done){7 var app = express();89 app.del('/', function(){});10 app.get('/users', function(req, res){});11 app.put('/users', function(req, res){});1213 request(app)14 .options('/users')15 .expect('GET,PUT')16 .expect('Allow', 'GET,PUT', done);17 })

Merge pull request #1868 from dpatti/smarter-router-auto-optionsRoman Shtylmanbefore adoption5ddbb69

line 18why, one step back
18

tests: add test for OPTIONS in app.allDouglas Christopher Wilsonbefore adoption0ebfc6b

lines 19–36why, one step back
19 it('should not be affected by app.all', function(done){
20 var app = express();2122 app.get('/', function(){});23 app.get('/users', function(req, res){});24 app.put('/users', function(req, res){});25 app.all('/users', function(req, res, next){26 res.setHeader('x-hit', '1');27 next();28 });2930 request(app)31 .options('/users')32 .expect('x-hit', '1')33 .expect('allow', 'GET,PUT')34 .expect(200, 'GET,PUT', done);35 })36

Merge pull request #1868 from dpatti/smarter-router-auto-optionsRoman Shtylmanbefore adoption5ddbb69

lines 37–51why, one step back
37 it('should not respond if the path is not defined', function(done){
38 var app = express();3940 app.get('/users', function(req, res){});4142 request(app)43 .options('/other')44 .expect(404, done);45 })4647 it('should forward requests down the middleware chain', function(done){48 var app = express();49 var router = new express.Router();5051 router.get('/users', function(req, res){});

make express.Router() return a Router function instanceRoman Shtylmanbefore adoptionf8b954b

line 52why, one step back
52 app.use(router);

Merge pull request #1868 from dpatti/smarter-router-auto-optionsRoman Shtylmanbefore adoption5ddbb69

lines 53–59why, one step back
53 app.get('/other', function(req, res){});
5455 request(app)56 .options('/other')57 .expect('GET')58 .expect('Allow', 'GET', done);59 })

Merge pull request #1877 from reqshark/masterTJ Holowaychukbefore adoptiondc5932d

lines 60–79why, one step back
60})
6162describe('app.options()', function(){63 it('should override the default behavior', function(done){64 var app = express();6566 app.options('/users', function(req, res){67 res.set('Allow', 'GET');68 res.send('GET');69 });7071 app.get('/users', function(req, res){});72 app.put('/users', function(req, res){});7374 request(app)75 .options('/users')76 .expect('GET')77 .expect('Allow', 'GET', done);78 })79})