Aktueller Stand

This commit is contained in:
2026-01-22 19:05:45 +01:00
parent 85dee61a4d
commit e280e4eadb
1967 changed files with 397327 additions and 74093 deletions

View File

@@ -1,7 +1,6 @@
'use strict'
const t = require('tap')
const test = t.test
const { test } = require('node:test')
const FindMyWay = require('../')
test('the router is an object with methods', t => {
@@ -9,17 +8,17 @@ test('the router is an object with methods', t => {
const findMyWay = FindMyWay()
t.equal(typeof findMyWay.on, 'function')
t.equal(typeof findMyWay.off, 'function')
t.equal(typeof findMyWay.lookup, 'function')
t.equal(typeof findMyWay.find, 'function')
t.assert.equal(typeof findMyWay.on, 'function')
t.assert.equal(typeof findMyWay.off, 'function')
t.assert.equal(typeof findMyWay.lookup, 'function')
t.assert.equal(typeof findMyWay.find, 'function')
})
test('on throws for invalid method', t => {
t.plan(1)
const findMyWay = FindMyWay()
t.throws(() => {
t.assert.throws(() => {
findMyWay.on('INVALID', '/a/b')
})
})
@@ -29,17 +28,17 @@ test('on throws for invalid path', t => {
const findMyWay = FindMyWay()
// Non string
t.throws(() => {
t.assert.throws(() => {
findMyWay.on('GET', 1)
})
// Empty
t.throws(() => {
t.assert.throws(() => {
findMyWay.on('GET', '')
})
// Doesn't start with / or *
t.throws(() => {
t.assert.throws(() => {
findMyWay.on('GET', 'invalid')
})
})
@@ -49,7 +48,7 @@ test('register a route', t => {
const findMyWay = FindMyWay()
findMyWay.on('GET', '/test', () => {
t.ok('inside the handler')
t.assert.ok('inside the handler')
})
findMyWay.lookup({ method: 'GET', url: '/test', headers: {} }, null)
@@ -60,7 +59,7 @@ test('register a route with multiple methods', t => {
const findMyWay = FindMyWay()
findMyWay.on(['GET', 'POST'], '/test', () => {
t.ok('inside the handler')
t.assert.ok('inside the handler')
})
findMyWay.lookup({ method: 'GET', url: '/test', headers: {} }, null)
@@ -74,7 +73,7 @@ test('does not register /test/*/ when ignoreTrailingSlash is true', t => {
})
findMyWay.on('GET', '/test/*', () => {})
t.equal(
t.assert.equal(
findMyWay.routes.filter((r) => r.path.includes('/test')).length,
1
)
@@ -84,7 +83,7 @@ test('off throws for invalid method', t => {
t.plan(1)
const findMyWay = FindMyWay()
t.throws(() => {
t.assert.throws(() => {
findMyWay.off('INVALID', '/a/b')
})
})
@@ -94,17 +93,17 @@ test('off throws for invalid path', t => {
const findMyWay = FindMyWay()
// Non string
t.throws(() => {
t.assert.throws(() => {
findMyWay.off('GET', 1)
})
// Empty
t.throws(() => {
t.assert.throws(() => {
findMyWay.off('GET', '')
})
// Doesn't start with / or *
t.throws(() => {
t.assert.throws(() => {
findMyWay.off('GET', 'invalid')
})
})
@@ -113,12 +112,12 @@ test('off with nested wildcards with parametric and static', t => {
t.plan(3)
const findMyWay = FindMyWay({
defaultRoute: (req, res) => {
t.fail('we should not be here, the url is: ' + req.url)
t.assert.fail('we should not be here, the url is: ' + req.url)
}
})
findMyWay.on('GET', '*', (req, res, params) => {
t.equal(params['*'], '/foo2/first/second')
t.assert.equal(params['*'], '/foo2/first/second')
})
findMyWay.on('GET', '/foo1/*', () => {})
findMyWay.on('GET', '/foo2/*', () => {})
@@ -127,12 +126,12 @@ test('off with nested wildcards with parametric and static', t => {
findMyWay.on('GET', '/foo4/param/hello/test/long/route', () => {})
const route1 = findMyWay.find('GET', '/foo3/first/second')
t.equal(route1.params['*'], 'first/second')
t.assert.equal(route1.params['*'], 'first/second')
findMyWay.off('GET', '/foo3/*')
const route2 = findMyWay.find('GET', '/foo3/first/second')
t.equal(route2.params['*'], '/foo3/first/second')
t.assert.equal(route2.params['*'], '/foo3/first/second')
findMyWay.off('GET', '/foo2/*')
findMyWay.lookup(
@@ -148,24 +147,24 @@ test('off removes all routes when ignoreTrailingSlash is true', t => {
})
findMyWay.on('GET', '/test1/', () => {})
t.equal(findMyWay.routes.length, 1)
t.assert.equal(findMyWay.routes.length, 1)
findMyWay.on('GET', '/test2', () => {})
t.equal(findMyWay.routes.length, 2)
t.assert.equal(findMyWay.routes.length, 2)
findMyWay.off('GET', '/test1')
t.equal(findMyWay.routes.length, 1)
t.equal(
t.assert.equal(findMyWay.routes.length, 1)
t.assert.equal(
findMyWay.routes.filter((r) => r.path === '/test2').length,
1
)
t.equal(
t.assert.equal(
findMyWay.routes.filter((r) => r.path === '/test2/').length,
0
)
findMyWay.off('GET', '/test2/')
t.equal(findMyWay.routes.length, 0)
t.assert.equal(findMyWay.routes.length, 0)
})
test('off removes all routes when ignoreDuplicateSlashes is true', t => {
@@ -175,24 +174,24 @@ test('off removes all routes when ignoreDuplicateSlashes is true', t => {
})
findMyWay.on('GET', '//test1', () => {})
t.equal(findMyWay.routes.length, 1)
t.assert.equal(findMyWay.routes.length, 1)
findMyWay.on('GET', '/test2', () => {})
t.equal(findMyWay.routes.length, 2)
t.assert.equal(findMyWay.routes.length, 2)
findMyWay.off('GET', '/test1')
t.equal(findMyWay.routes.length, 1)
t.equal(
t.assert.equal(findMyWay.routes.length, 1)
t.assert.equal(
findMyWay.routes.filter((r) => r.path === '/test2').length,
1
)
t.equal(
t.assert.equal(
findMyWay.routes.filter((r) => r.path === '//test2').length,
0
)
findMyWay.off('GET', '//test2')
t.equal(findMyWay.routes.length, 0)
t.assert.equal(findMyWay.routes.length, 0)
})
test('deregister a route without children', t => {
@@ -203,8 +202,8 @@ test('deregister a route without children', t => {
findMyWay.on('GET', '/a/b', () => {})
findMyWay.off('GET', '/a/b')
t.ok(findMyWay.find('GET', '/a'))
t.notOk(findMyWay.find('GET', '/a/b'))
t.assert.ok(findMyWay.find('GET', '/a'))
t.assert.ok(!findMyWay.find('GET', '/a/b'))
})
test('deregister a route with children', t => {
@@ -215,8 +214,8 @@ test('deregister a route with children', t => {
findMyWay.on('GET', '/a/b', () => {})
findMyWay.off('GET', '/a')
t.notOk(findMyWay.find('GET', '/a'))
t.ok(findMyWay.find('GET', '/a/b'))
t.assert.ok(!findMyWay.find('GET', '/a'))
t.assert.ok(findMyWay.find('GET', '/a/b'))
})
test('deregister a route by method', t => {
@@ -226,8 +225,8 @@ test('deregister a route by method', t => {
findMyWay.on(['GET', 'POST'], '/a', () => {})
findMyWay.off('GET', '/a')
t.notOk(findMyWay.find('GET', '/a'))
t.ok(findMyWay.find('POST', '/a'))
t.assert.ok(!findMyWay.find('GET', '/a'))
t.assert.ok(findMyWay.find('POST', '/a'))
})
test('deregister a route with multiple methods', t => {
@@ -237,8 +236,8 @@ test('deregister a route with multiple methods', t => {
findMyWay.on(['GET', 'POST'], '/a', () => {})
findMyWay.off(['GET', 'POST'], '/a')
t.notOk(findMyWay.find('GET', '/a'))
t.notOk(findMyWay.find('POST', '/a'))
t.assert.ok(!findMyWay.find('GET', '/a'))
t.assert.ok(!findMyWay.find('POST', '/a'))
})
test('reset a router', t => {
@@ -248,8 +247,8 @@ test('reset a router', t => {
findMyWay.on(['GET', 'POST'], '/a', () => {})
findMyWay.reset()
t.notOk(findMyWay.find('GET', '/a'))
t.notOk(findMyWay.find('POST', '/a'))
t.assert.ok(!findMyWay.find('GET', '/a'))
t.assert.ok(!findMyWay.find('POST', '/a'))
})
test('default route', t => {
@@ -257,7 +256,7 @@ test('default route', t => {
const findMyWay = FindMyWay({
defaultRoute: () => {
t.ok('inside the default route')
t.assert.ok('inside the default route')
}
})
@@ -269,7 +268,7 @@ test('parametric route', t => {
const findMyWay = FindMyWay()
findMyWay.on('GET', '/test/:id', (req, res, params) => {
t.equal(params.id, 'hello')
t.assert.equal(params.id, 'hello')
})
findMyWay.lookup({ method: 'GET', url: '/test/hello', headers: {} }, null)
@@ -280,11 +279,11 @@ test('multiple parametric route', t => {
const findMyWay = FindMyWay()
findMyWay.on('GET', '/test/:id', (req, res, params) => {
t.equal(params.id, 'hello')
t.assert.equal(params.id, 'hello')
})
findMyWay.on('GET', '/other-test/:id', (req, res, params) => {
t.equal(params.id, 'world')
t.assert.equal(params.id, 'world')
})
findMyWay.lookup({ method: 'GET', url: '/test/hello', headers: {} }, null)
@@ -296,11 +295,11 @@ test('multiple parametric route with the same prefix', t => {
const findMyWay = FindMyWay()
findMyWay.on('GET', '/test/:id', (req, res, params) => {
t.equal(params.id, 'hello')
t.assert.equal(params.id, 'hello')
})
findMyWay.on('GET', '/test/:id/world', (req, res, params) => {
t.equal(params.id, 'world')
t.assert.equal(params.id, 'world')
})
findMyWay.lookup({ method: 'GET', url: '/test/hello', headers: {} }, null)
@@ -312,8 +311,8 @@ test('nested parametric route', t => {
const findMyWay = FindMyWay()
findMyWay.on('GET', '/test/:hello/test/:world', (req, res, params) => {
t.equal(params.hello, 'hello')
t.equal(params.world, 'world')
t.assert.equal(params.hello, 'hello')
t.assert.equal(params.world, 'world')
})
findMyWay.lookup({ method: 'GET', url: '/test/hello/test/world', headers: {} }, null)
@@ -324,12 +323,12 @@ test('nested parametric route with same prefix', t => {
const findMyWay = FindMyWay()
findMyWay.on('GET', '/test', (req, res, params) => {
t.ok('inside route')
t.assert.ok('inside route')
})
findMyWay.on('GET', '/test/:hello/test/:world', (req, res, params) => {
t.equal(params.hello, 'hello')
t.equal(params.world, 'world')
t.assert.equal(params.hello, 'hello')
t.assert.equal(params.world, 'world')
})
findMyWay.lookup({ method: 'GET', url: '/test', headers: {} }, null)
@@ -341,7 +340,7 @@ test('long route', t => {
const findMyWay = FindMyWay()
findMyWay.on('GET', '/abc/def/ghi/lmn/opq/rst/uvz', (req, res, params) => {
t.ok('inside long path')
t.assert.ok('inside long path')
})
findMyWay.lookup({ method: 'GET', url: '/abc/def/ghi/lmn/opq/rst/uvz', headers: {} }, null)
@@ -352,9 +351,9 @@ test('long parametric route', t => {
const findMyWay = FindMyWay()
findMyWay.on('GET', '/abc/:def/ghi/:lmn/opq/:rst/uvz', (req, res, params) => {
t.equal(params.def, 'def')
t.equal(params.lmn, 'lmn')
t.equal(params.rst, 'rst')
t.assert.equal(params.def, 'def')
t.assert.equal(params.lmn, 'lmn')
t.assert.equal(params.rst, 'rst')
})
findMyWay.lookup({ method: 'GET', url: '/abc/def/ghi/lmn/opq/rst/uvz', headers: {} }, null)
@@ -373,24 +372,24 @@ test('long parametric route with common prefix', t => {
})
findMyWay.on('GET', '/abc/:def', (req, res, params) => {
t.equal(params.def, 'def')
t.assert.equal(params.def, 'def')
})
findMyWay.on('GET', '/abc/:def/ghi/:lmn', (req, res, params) => {
t.equal(params.def, 'def')
t.equal(params.lmn, 'lmn')
t.assert.equal(params.def, 'def')
t.assert.equal(params.lmn, 'lmn')
})
findMyWay.on('GET', '/abc/:def/ghi/:lmn/opq/:rst', (req, res, params) => {
t.equal(params.def, 'def')
t.equal(params.lmn, 'lmn')
t.equal(params.rst, 'rst')
t.assert.equal(params.def, 'def')
t.assert.equal(params.lmn, 'lmn')
t.assert.equal(params.rst, 'rst')
})
findMyWay.on('GET', '/abc/:def/ghi/:lmn/opq/:rst/uvz', (req, res, params) => {
t.equal(params.def, 'def')
t.equal(params.lmn, 'lmn')
t.equal(params.rst, 'rst')
t.assert.equal(params.def, 'def')
t.assert.equal(params.lmn, 'lmn')
t.assert.equal(params.rst, 'rst')
})
findMyWay.lookup({ method: 'GET', url: '/abc/def', headers: {} }, null)
@@ -404,19 +403,19 @@ test('common prefix', t => {
const findMyWay = FindMyWay()
findMyWay.on('GET', '/f', (req, res, params) => {
t.ok('inside route')
t.assert.ok('inside route')
})
findMyWay.on('GET', '/ff', (req, res, params) => {
t.ok('inside route')
t.assert.ok('inside route')
})
findMyWay.on('GET', '/ffa', (req, res, params) => {
t.ok('inside route')
t.assert.ok('inside route')
})
findMyWay.on('GET', '/ffb', (req, res, params) => {
t.ok('inside route')
t.assert.ok('inside route')
})
findMyWay.lookup({ method: 'GET', url: '/f', headers: {} }, null)
@@ -430,7 +429,7 @@ test('wildcard', t => {
const findMyWay = FindMyWay()
findMyWay.on('GET', '/test/*', (req, res, params) => {
t.equal(params['*'], 'hello')
t.assert.equal(params['*'], 'hello')
})
findMyWay.lookup(
@@ -444,7 +443,7 @@ test('catch all wildcard', t => {
const findMyWay = FindMyWay()
findMyWay.on('GET', '*', (req, res, params) => {
t.equal(params['*'], '/test/hello')
t.assert.equal(params['*'], '/test/hello')
})
findMyWay.lookup(
@@ -460,7 +459,7 @@ test('find should return the route', t => {
findMyWay.on('GET', '/test', fn)
t.same(
t.assert.deepEqual(
findMyWay.find('GET', '/test'),
{ handler: fn, params: {}, store: null, searchParams: {} }
)
@@ -473,7 +472,7 @@ test('find should return the route with params', t => {
findMyWay.on('GET', '/test/:id', fn)
t.same(
t.assert.deepEqual(
findMyWay.find('GET', '/test/hello'),
{ handler: fn, params: { id: 'hello' }, store: null, searchParams: {} }
)
@@ -483,7 +482,7 @@ test('find should return a null handler if the route does not exist', t => {
t.plan(1)
const findMyWay = FindMyWay()
t.same(
t.assert.deepEqual(
findMyWay.find('GET', '/test'),
null
)
@@ -496,7 +495,7 @@ test('should decode the uri - parametric', t => {
findMyWay.on('GET', '/test/:id', fn)
t.same(
t.assert.deepEqual(
findMyWay.find('GET', '/test/he%2Fllo'),
{ handler: fn, params: { id: 'he/llo' }, store: null, searchParams: {} }
)
@@ -509,7 +508,7 @@ test('should decode the uri - wildcard', t => {
findMyWay.on('GET', '/test/*', fn)
t.same(
t.assert.deepEqual(
findMyWay.find('GET', '/test/he%2Fllo'),
{ handler: fn, params: { '*': 'he/llo' }, store: null, searchParams: {} }
)
@@ -522,7 +521,7 @@ test('safe decodeURIComponent', t => {
findMyWay.on('GET', '/test/:id', fn)
t.same(
t.assert.deepEqual(
findMyWay.find('GET', '/test/hel%"Flo'),
null
)
@@ -535,7 +534,7 @@ test('safe decodeURIComponent - nested route', t => {
findMyWay.on('GET', '/test/hello/world/:id/blah', fn)
t.same(
t.assert.deepEqual(
findMyWay.find('GET', '/test/hello/world/hel%"Flo/blah'),
null
)
@@ -548,7 +547,7 @@ test('safe decodeURIComponent - wildcard', t => {
findMyWay.on('GET', '/test/*', fn)
t.same(
t.assert.deepEqual(
findMyWay.find('GET', '/test/hel%"Flo'),
null
)
@@ -559,11 +558,11 @@ test('static routes should be inserted before parametric / 1', t => {
const findMyWay = FindMyWay()
findMyWay.on('GET', '/test/hello', () => {
t.pass('inside correct handler')
t.assert.ok('inside correct handler')
})
findMyWay.on('GET', '/test/:id', () => {
t.fail('wrong handler')
t.assert.fail('wrong handler')
})
findMyWay.lookup({ method: 'GET', url: '/test/hello', headers: {} }, null)
@@ -574,11 +573,11 @@ test('static routes should be inserted before parametric / 2', t => {
const findMyWay = FindMyWay()
findMyWay.on('GET', '/test/:id', () => {
t.fail('wrong handler')
t.assert.fail('wrong handler')
})
findMyWay.on('GET', '/test/hello', () => {
t.pass('inside correct handler')
t.assert.ok('inside correct handler')
})
findMyWay.lookup({ method: 'GET', url: '/test/hello', headers: {} }, null)
@@ -589,19 +588,19 @@ test('static routes should be inserted before parametric / 3', t => {
const findMyWay = FindMyWay()
findMyWay.on('GET', '/:id', () => {
t.fail('wrong handler')
t.assert.fail('wrong handler')
})
findMyWay.on('GET', '/test', () => {
t.ok('inside correct handler')
t.assert.ok('inside correct handler')
})
findMyWay.on('GET', '/test/:id', () => {
t.fail('wrong handler')
t.assert.fail('wrong handler')
})
findMyWay.on('GET', '/test/hello', () => {
t.ok('inside correct handler')
t.assert.ok('inside correct handler')
})
findMyWay.lookup({ method: 'GET', url: '/test', headers: {} }, null)
@@ -613,19 +612,19 @@ test('static routes should be inserted before parametric / 4', t => {
const findMyWay = FindMyWay()
findMyWay.on('GET', '/:id', () => {
t.ok('inside correct handler')
t.assert.ok('inside correct handler')
})
findMyWay.on('GET', '/test', () => {
t.fail('wrong handler')
t.assert.fail('wrong handler')
})
findMyWay.on('GET', '/test/:id', () => {
t.ok('inside correct handler')
t.assert.ok('inside correct handler')
})
findMyWay.on('GET', '/test/hello', () => {
t.fail('wrong handler')
t.assert.fail('wrong handler')
})
findMyWay.lookup({ method: 'GET', url: '/test/id', headers: {} }, null)
@@ -637,16 +636,16 @@ test('Static parametric with shared part of the path', t => {
const findMyWay = FindMyWay({
defaultRoute: (req, res) => {
t.equal(req.url, '/example/shared/nested/oopss')
t.assert.equal(req.url, '/example/shared/nested/oopss')
}
})
findMyWay.on('GET', '/example/shared/nested/test', (req, res, params) => {
t.fail('We should not be here')
t.assert.fail('We should not be here')
})
findMyWay.on('GET', '/example/:param/nested/oops', (req, res, params) => {
t.equal(params.param, 'other')
t.assert.equal(params.param, 'other')
})
findMyWay.lookup({ method: 'GET', url: '/example/shared/nested/oopss', headers: {} }, null)
@@ -658,18 +657,18 @@ test('parametric route with different method', t => {
const findMyWay = FindMyWay()
findMyWay.on('GET', '/test/:id', (req, res, params) => {
t.equal(params.id, 'hello')
t.assert.equal(params.id, 'hello')
})
findMyWay.on('POST', '/test/:other', (req, res, params) => {
t.equal(params.other, 'world')
t.assert.equal(params.other, 'world')
})
findMyWay.lookup({ method: 'GET', url: '/test/hello', headers: {} }, null)
findMyWay.lookup({ method: 'POST', url: '/test/world', headers: {} }, null)
})
test('params does not keep the object reference', t => {
test('params does not keep the object reference', (t, done) => {
t.plan(2)
const findMyWay = FindMyWay()
let first = true
@@ -677,11 +676,12 @@ test('params does not keep the object reference', t => {
findMyWay.on('GET', '/test/:id', (req, res, params) => {
if (first) {
setTimeout(() => {
t.equal(params.id, 'hello')
t.assert.equal(params.id, 'hello')
}, 10)
} else {
setTimeout(() => {
t.equal(params.id, 'world')
t.assert.equal(params.id, 'world')
done()
}, 10)
}
first = false
@@ -695,12 +695,12 @@ test('Unsupported method (static)', t => {
t.plan(1)
const findMyWay = FindMyWay({
defaultRoute: (req, res) => {
t.pass('Everything ok')
t.assert.ok('Everything ok')
}
})
findMyWay.on('GET', '/', (req, res, params) => {
t.fail('We should not be here')
t.assert.fail('We should not be here')
})
findMyWay.lookup({ method: 'TROLL', url: '/', headers: {} }, null)
@@ -710,12 +710,12 @@ test('Unsupported method (wildcard)', t => {
t.plan(1)
const findMyWay = FindMyWay({
defaultRoute: (req, res) => {
t.pass('Everything ok')
t.assert.ok('Everything ok')
}
})
findMyWay.on('GET', '*', (req, res, params) => {
t.fail('We should not be here')
t.assert.fail('We should not be here')
})
findMyWay.lookup({ method: 'TROLL', url: '/hello/world', headers: {} }, null)
@@ -727,7 +727,7 @@ test('Unsupported method (static find)', t => {
findMyWay.on('GET', '/', () => {})
t.same(findMyWay.find('TROLL', '/'), null)
t.assert.deepEqual(findMyWay.find('TROLL', '/'), null)
})
test('Unsupported method (wildcard find)', t => {
@@ -736,7 +736,7 @@ test('Unsupported method (wildcard find)', t => {
findMyWay.on('GET', '*', () => {})
t.same(findMyWay.find('TROLL', '/hello/world'), null)
t.assert.deepEqual(findMyWay.find('TROLL', '/hello/world'), null)
})
test('register all known HTTP methods', t => {
@@ -751,14 +751,14 @@ test('register all known HTTP methods', t => {
findMyWay.on(m, '/test', handlers[m])
}
t.ok(findMyWay.find('COPY', '/test'))
t.equal(findMyWay.find('COPY', '/test').handler, handlers.COPY)
t.assert.ok(findMyWay.find('COPY', '/test'))
t.assert.equal(findMyWay.find('COPY', '/test').handler, handlers.COPY)
t.ok(findMyWay.find('SUBSCRIBE', '/test'))
t.equal(findMyWay.find('SUBSCRIBE', '/test').handler, handlers.SUBSCRIBE)
t.assert.ok(findMyWay.find('SUBSCRIBE', '/test'))
t.assert.equal(findMyWay.find('SUBSCRIBE', '/test').handler, handlers.SUBSCRIBE)
t.ok(findMyWay.find('M-SEARCH', '/test'))
t.equal(findMyWay.find('M-SEARCH', '/test').handler, handlers['M-SEARCH'])
t.assert.ok(findMyWay.find('M-SEARCH', '/test'))
t.assert.equal(findMyWay.find('M-SEARCH', '/test').handler, handlers['M-SEARCH'])
})
test('off removes all routes without checking constraints if no constraints are specified', t => {
@@ -771,7 +771,7 @@ test('off removes all routes without checking constraints if no constraints are
findMyWay.off('GET', '/test')
t.equal(findMyWay.routes.length, 0)
t.assert.equal(findMyWay.routes.length, 0)
})
test('off removes only constrainted routes if constraints are specified', t => {
@@ -784,8 +784,8 @@ test('off removes only constrainted routes if constraints are specified', t => {
findMyWay.off('GET', '/test', { host: 'example.com' })
t.equal(findMyWay.routes.length, 1)
t.notOk(findMyWay.routes[0].opts.constraints)
t.assert.equal(findMyWay.routes.length, 1)
t.assert.ok(!findMyWay.routes[0].opts.constraints)
})
test('off removes no routes if provided constraints does not match any registered route', t => {
@@ -799,7 +799,7 @@ test('off removes no routes if provided constraints does not match any registere
findMyWay.off('GET', '/test', { version: '1.x' })
t.equal(findMyWay.routes.length, 3)
t.assert.equal(findMyWay.routes.length, 3)
})
test('off validates that constraints is an object or undefined', t => {
@@ -807,12 +807,12 @@ test('off validates that constraints is an object or undefined', t => {
const findMyWay = FindMyWay()
t.throws(() => findMyWay.off('GET', '/', 2))
t.throws(() => findMyWay.off('GET', '/', 'should throw'))
t.throws(() => findMyWay.off('GET', '/', []))
t.doesNotThrow(() => findMyWay.off('GET', '/', undefined))
t.doesNotThrow(() => findMyWay.off('GET', '/', {}))
t.doesNotThrow(() => findMyWay.off('GET', '/'))
t.assert.throws(() => findMyWay.off('GET', '/', 2))
t.assert.throws(() => findMyWay.off('GET', '/', 'should throw'))
t.assert.throws(() => findMyWay.off('GET', '/', []))
t.assert.doesNotThrow(() => findMyWay.off('GET', '/', undefined))
t.assert.doesNotThrow(() => findMyWay.off('GET', '/', {}))
t.assert.doesNotThrow(() => findMyWay.off('GET', '/'))
})
test('off removes only unconstrainted route if an empty object is given as constraints', t => {
@@ -825,6 +825,6 @@ test('off removes only unconstrainted route if an empty object is given as const
findMyWay.off('GET', '/', {})
t.equal(findMyWay.routes.length, 1)
t.equal(findMyWay.routes[0].opts.constraints.host, 'fastify.io')
t.assert.equal(findMyWay.routes.length, 1)
t.assert.equal(findMyWay.routes[0].opts.constraints.host, 'fastify.io')
})