-
Notifications
You must be signed in to change notification settings - Fork 140
/
issue-285.test.js
38 lines (28 loc) · 1.19 KB
/
issue-285.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'use strict'
const t = require('tap')
const test = t.test
const FindMyWay = require('../')
test('Parametric regex match with similar routes', (t) => {
t.plan(2)
const findMyWay = FindMyWay()
findMyWay.on('GET', '/:a(a)', () => {})
findMyWay.on('GET', '/:param/static', () => {})
t.same(findMyWay.find('GET', '/a', {}).params, { a: 'a' })
t.same(findMyWay.find('GET', '/param/static', {}).params, { param: 'param' })
})
test('Parametric regex match with similar routes', (t) => {
t.plan(2)
const findMyWay = FindMyWay()
findMyWay.on('GET', '/:a(a)', () => {})
findMyWay.on('GET', '/:b(b)/static', () => {})
t.same(findMyWay.find('GET', '/a', {}).params, { a: 'a' })
t.same(findMyWay.find('GET', '/b/static', {}).params, { b: 'b' })
})
test('Parametric regex match with similar routes', (t) => {
t.plan(2)
const findMyWay = FindMyWay()
findMyWay.on('GET', '/:a(a)/static', { constraints: { version: '1.0.0' } }, () => {})
findMyWay.on('GET', '/:b(b)/static', { constraints: { version: '2.0.0' } }, () => {})
t.same(findMyWay.find('GET', '/a/static', { version: '1.0.0' }).params, { a: 'a' })
t.same(findMyWay.find('GET', '/b/static', { version: '2.0.0' }).params, { b: 'b' })
})