fastify
Version:
Fast and low overhead web framework, for Node.js
54 lines (43 loc) • 1.11 kB
JavaScript
const t = require('tap')
const test = t.test
const Fastify = require('..')
test('listen should accept null port', t => {
t.plan(1)
const fastify = Fastify()
t.teardown(fastify.close.bind(fastify))
fastify.listen({ port: null }, (err) => {
t.error(err)
})
})
test('listen should accept undefined port', t => {
t.plan(1)
const fastify = Fastify()
t.teardown(fastify.close.bind(fastify))
fastify.listen({ port: undefined }, (err) => {
t.error(err)
})
})
test('listen should accept stringified number port', t => {
t.plan(1)
const fastify = Fastify()
t.teardown(fastify.close.bind(fastify))
fastify.listen({ port: '1234' }, (err) => {
t.error(err)
})
})
test('listen should reject string port', async (t) => {
t.plan(2)
const fastify = Fastify()
t.teardown(fastify.close.bind(fastify))
try {
await fastify.listen({ port: 'hello-world' })
} catch (error) {
t.equal(error.code, 'ERR_SOCKET_BAD_PORT')
}
try {
await fastify.listen({ port: '1234hello' })
} catch (error) {
t.equal(error.code, 'ERR_SOCKET_BAD_PORT')
}
})