|
| 1 | +'use strict' |
| 2 | + |
| 3 | +const t = require('tap') |
| 4 | +const FindMyWay = require('../') |
| 5 | + |
| 6 | +t.test('path params match', (t) => { |
| 7 | + t.plan(12) |
| 8 | + |
| 9 | + const findMyWay = FindMyWay({ ignoreTrailingSlash: true }) |
| 10 | + |
| 11 | + const b1Path = function b1StaticPath () {} |
| 12 | + const b2Path = function b2StaticPath () {} |
| 13 | + const cPath = function cStaticPath () {} |
| 14 | + const paramPath = function parameterPath () {} |
| 15 | + |
| 16 | + findMyWay.on('GET', '/ab1', b1Path) |
| 17 | + findMyWay.on('GET', '/ab2', b2Path) |
| 18 | + findMyWay.on('GET', '/ac', cPath) |
| 19 | + findMyWay.on('GET', '/:pam', paramPath) |
| 20 | + |
| 21 | + t.equals(findMyWay.find('GET', '/ab1').handler, b1Path) |
| 22 | + t.equals(findMyWay.find('GET', '/ab1/').handler, b1Path) |
| 23 | + t.equals(findMyWay.find('GET', '/ab2').handler, b2Path) |
| 24 | + t.equals(findMyWay.find('GET', '/ab2/').handler, b2Path) |
| 25 | + t.equals(findMyWay.find('GET', '/ac').handler, cPath) |
| 26 | + t.equals(findMyWay.find('GET', '/ac/').handler, cPath) |
| 27 | + t.equals(findMyWay.find('GET', '/foo').handler, paramPath) |
| 28 | + t.equals(findMyWay.find('GET', '/foo/').handler, paramPath) |
| 29 | + |
| 30 | + const noTrailingSlashRet = findMyWay.find('GET', '/abcdef') |
| 31 | + t.equals(noTrailingSlashRet.handler, paramPath) |
| 32 | + t.deepEqual(noTrailingSlashRet.params, { pam: 'abcdef' }) |
| 33 | + |
| 34 | + const trailingSlashRet = findMyWay.find('GET', '/abcdef/') |
| 35 | + t.equals(trailingSlashRet.handler, paramPath) |
| 36 | + t.deepEqual(trailingSlashRet.params, { pam: 'abcdef' }) |
| 37 | +}) |
0 commit comments