Buckets:
| const { test, describe } = require('node:test') | |
| const Fastify = require('..') | |
| const fastify = Fastify() | |
| describe('hasRoute', async t => { | |
| test('hasRoute - invalid options', t => { | |
| t.plan(3) | |
| t.assert.strictEqual(fastify.hasRoute({ }), false) | |
| t.assert.strictEqual(fastify.hasRoute({ method: 'GET' }), false) | |
| t.assert.strictEqual(fastify.hasRoute({ constraints: [] }), false) | |
| }) | |
| test('hasRoute - primitive method', t => { | |
| t.plan(2) | |
| fastify.route({ | |
| method: 'GET', | |
| url: '/', | |
| handler: function (req, reply) { | |
| reply.send({ hello: 'world' }) | |
| } | |
| }) | |
| t.assert.strictEqual(fastify.hasRoute({ | |
| method: 'GET', | |
| url: '/' | |
| }), true) | |
| t.assert.strictEqual(fastify.hasRoute({ | |
| method: 'POST', | |
| url: '/' | |
| }), false) | |
| }) | |
| test('hasRoute - with constraints', t => { | |
| t.plan(2) | |
| fastify.route({ | |
| method: 'GET', | |
| url: '/', | |
| constraints: { version: '1.2.0' }, | |
| handler: (req, reply) => { | |
| reply.send({ hello: 'world' }) | |
| } | |
| }) | |
| t.assert.strictEqual(fastify.hasRoute({ | |
| method: 'GET', | |
| url: '/', | |
| constraints: { version: '1.2.0' } | |
| }), true) | |
| t.assert.strictEqual(fastify.hasRoute({ | |
| method: 'GET', | |
| url: '/', | |
| constraints: { version: '1.3.0' } | |
| }), false) | |
| }) | |
| test('hasRoute - parametric route regexp with constraints', t => { | |
| t.plan(1) | |
| // parametric with regexp | |
| fastify.get('/example/:file(^\\d+).png', function (request, reply) { }) | |
| t.assert.strictEqual(fastify.hasRoute({ | |
| method: 'GET', | |
| url: '/example/:file(^\\d+).png' | |
| }), true) | |
| }) | |
| test('hasRoute - finds a route even if method is not uppercased', t => { | |
| t.plan(1) | |
| fastify.route({ | |
| method: 'GET', | |
| url: '/equal', | |
| handler: function (req, reply) { | |
| reply.send({ hello: 'world' }) | |
| } | |
| }) | |
| t.assert.strictEqual(fastify.hasRoute({ | |
| method: 'get', | |
| url: '/equal' | |
| }), true) | |
| }) | |
| }) | |
Xet Storage Details
- Size:
- 2.01 kB
- Xet hash:
- 2dc465dd8e04eec812ebe05ec3ec728b476f4049e773f4ac3fe4bc7c398bf0c8
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.