Skip to content

Commit

Permalink
Put test behind a compat flag
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeembrey committed Apr 16, 2024
1 parent ee43218 commit efc788a
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions test/app.router.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,19 +188,21 @@ describe('app.router', function(){
.expect('editing user 10', done);
})

it('should populate req.params with named captures', function(done){
var app = express();
if (supportsRegexp('(?<foo>.*)')) {
it('should populate req.params with named captures', function(done){
var app = express();

app.get(/^\/user\/(?<userId>[0-9]+)\/(view|edit)?$/, function(req, res){
var id = req.params.userId
, op = req.params[0];
res.end(op + 'ing user ' + id);
});
app.get(/^\/user\/(?<userId>[0-9]+)\/(view|edit)?$/, function(req, res){
var id = req.params.userId
, op = req.params[0];
res.end(op + 'ing user ' + id);
});

request(app)
.get('/user/10/edit')
.expect('editing user 10', done);
})
request(app)
.get('/user/10/edit')
.expect('editing user 10', done);
})
}

it('should ensure regexp matches path prefix', function (done) {
var app = express()
Expand Down Expand Up @@ -1123,3 +1125,12 @@ describe('app.router', function(){
assert.strictEqual(app.get('/', function () {}), app)
})
})

function supportsRegexp(source) {
try {
new RegExp(source)
return true
} catch (e) {
return false
}
}

0 comments on commit efc788a

Please sign in to comment.