strong-tie/inbound-calls
0
1'use strict'2 3const { test } = require('node:test')4const Fastify = require('..')5const {6 FST_ERR_DEC_ALREADY_PRESENT7} = require('../lib/errors')8 9test('Should be able to override the default use API', t => {10 t.plan(1)11 const fastify = Fastify()12 fastify.decorate('use', () => true)13 t.assert.strictEqual(fastify.use(), true)14})15 16test('Cannot decorate use twice', t => {17 t.plan(1)18 const fastify = Fastify()19 fastify.decorate('use', () => true)20 try {21 fastify.decorate('use', () => true)22 } catch (err) {23 t.assert.ok(err instanceof FST_ERR_DEC_ALREADY_PRESENT)24 }25})26 27test('Encapsulation works', t => {28 const fastify = Fastify()29 30 fastify.register((instance, opts, done) => {31 instance.decorate('use', () => true)32 t.assert.strictEqual(instance.use(), true)33 done()34 })35 36 fastify.ready()37})38 