Files
simple-mail-cleaner/backend/node_modules/find-my-way/test/issue-247.test.js
2026-01-22 15:49:12 +01:00

53 lines
2.2 KiB
JavaScript

'use strict'
const t = require('tap')
const test = t.test
const FindMyWay = require('..')
test('If there are constraints param, router.off method support filter', t => {
t.plan(12)
const findMyWay = FindMyWay()
findMyWay.on('GET', '/a', { constraints: { host: '1' } }, () => {}, { name: 1 })
findMyWay.on('GET', '/a', { constraints: { host: '2', version: '1.0.0' } }, () => {}, { name: 2 })
findMyWay.on('GET', '/a', { constraints: { host: '2', version: '2.0.0' } }, () => {}, { name: 3 })
t.same(findMyWay.find('GET', '/a', { host: '1' }).store, { name: 1 })
t.same(findMyWay.find('GET', '/a', { host: '2', version: '1.0.0' }).store, { name: 2 })
t.same(findMyWay.find('GET', '/a', { host: '2', version: '2.0.0' }).store, { name: 3 })
findMyWay.off('GET', '/a', { host: '1' })
t.same(findMyWay.find('GET', '/a', { host: '1' }), null)
t.same(findMyWay.find('GET', '/a', { host: '2', version: '1.0.0' }).store, { name: 2 })
t.same(findMyWay.find('GET', '/a', { host: '2', version: '2.0.0' }).store, { name: 3 })
findMyWay.off('GET', '/a', { host: '2', version: '1.0.0' })
t.same(findMyWay.find('GET', '/a', { host: '1' }), null)
t.same(findMyWay.find('GET', '/a', { host: '2', version: '1.0.0' }), null)
t.same(findMyWay.find('GET', '/a', { host: '2', version: '2.0.0' }).store, { name: 3 })
findMyWay.off('GET', '/a', { host: '2', version: '2.0.0' })
t.same(findMyWay.find('GET', '/a', { host: '1' }), null)
t.same(findMyWay.find('GET', '/a', { host: '2', version: '1.0.0' }), null)
t.same(findMyWay.find('GET', '/a', { host: '2', version: '2.0.0' }), null)
})
test('If there are no constraints param, router.off method remove all matched router', t => {
t.plan(4)
const findMyWay = FindMyWay()
findMyWay.on('GET', '/a', { constraints: { host: '1' } }, () => {}, { name: 1 })
findMyWay.on('GET', '/a', { constraints: { host: '2' } }, () => {}, { name: 2 })
t.same(findMyWay.find('GET', '/a', { host: '1' }).store, { name: 1 })
t.same(findMyWay.find('GET', '/a', { host: '2' }).store, { name: 2 })
findMyWay.off('GET', '/a')
t.same(findMyWay.find('GET', '/a', { host: '1' }), null)
t.same(findMyWay.find('GET', '/a', { host: '2' }), null)
})