router.test.ts
This file
Path
src/router/pattern-router/router.test.ts
42 lines 路 1.1 KiB 路 TypeScript
Last changed by
Not known.
History of this fileTake it
12345678910111213141516171819202122232425262728293031323334353637383940414243import { UnsupportedPathError } from '../../router'import { runTest } from '../common.case.test'import { PatternRouter } from './router'
describe('Pattern', () => { runTest({ skip: [ { reason: 'UnsupportedPath', tests: ['Duplicate param name > self'], }, { reason: 'PatternRouter allows trailing slashes', tests: ['Trailing slash > GET /book/'], }, ], newRouter: () => new PatternRouter(), })
describe('Duplicate param name', () => { it('self', () => { const router = new PatternRouter<string>() expect(() => { router.add('GET', '/:id/:id', 'foo') }).toThrowError(UnsupportedPathError) }) }) describe('Trailing slash', () => { const router = new PatternRouter<string>()
beforeEach(() => { router.add('GET', '/book', 'GET /book') router.add('GET', '/book/:id', 'GET /book/:id') })
it('GET /book/', () => { const [res] = router.match('GET', '/book/') expect(res.length).toBe(1) expect(res[0][0]).toBe('GET /book') }) })})