wzp
2021-05-13 7d694a9113118daec5be7ac224dab46a3b20f106
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
'use strict'
 
const t = require('tap')
const test = t.test
const FindMyWay = require('../')
 
test('Nested static parametric route, url with parameter common prefix > 1', t => {
  t.plan(1)
  const findMyWay = FindMyWay({
    defaultRoute: (req, res) => {
      t.fail('Should not be defaultRoute')
    }
  })
 
  findMyWay.on('GET', '/api/foo/b2', (req, res) => {
    res.end('{"message":"hello world"}')
  })
 
  findMyWay.on('GET', '/api/foo/bar/qux', (req, res) => {
    res.end('{"message":"hello world"}')
  })
 
  findMyWay.on('GET', '/api/foo/:id/bar', (req, res) => {
    res.end('{"message":"hello world"}')
  })
 
  findMyWay.on('GET', '/foo', (req, res) => {
    res.end('{"message":"hello world"}')
  })
 
  t.deepEqual(findMyWay.find('GET', '/api/foo/b-123/bar').params, { id: 'b-123' })
})