Skip to content

Commit e09b5f5

Browse files
authored
chore(index): add jsdoc types (#200)
1 parent bf19b77 commit e09b5f5

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,23 @@ const methodNames = [
1313
'type', 'types'
1414
]
1515

16+
/** @this {import('fastify').FastifyRequest} */
1617
function acceptsMethod () {
1718
if (!this.raw[acceptsObjectSymbol]) {
1819
this.raw[acceptsObjectSymbol] = accepts(this.raw)
1920
}
2021
return this.raw[acceptsObjectSymbol]
2122
}
2223

24+
/** @this {import('fastify').FastifyReply} */
2325
function replyAcceptMethod () {
2426
if (!this.request[acceptsObjectSymbol]) {
2527
this.request[acceptsObjectSymbol] = accepts(this.request.raw)
2628
}
2729
return this.request[acceptsObjectSymbol]
2830
}
2931

32+
/** @type {typeof import('./types/index').fastifyAccepts} */
3033
function fastifyAccepts (fastify, options, done) {
3134
fastify.decorateRequest('accepts', acceptsMethod)
3235

test/index.test.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const fastifyAccepts = require('..')
66

77
const Fastify = require('fastify')
88

9+
/** @typedef {import('node:test').TestContext} TestContext */
10+
911
const testCases = [
1012
{
1113
name: 'request - no header',
@@ -88,7 +90,7 @@ const testCases = [
8890
}
8991
]
9092

91-
test('accept header', async t => {
93+
test('accept header', async (/** @type {TestContext} */ t) => {
9294
t.plan(testCases.length)
9395

9496
const fastify = Fastify()
@@ -120,7 +122,7 @@ test('accept header', async t => {
120122
const BASE_URL = `http://localhost:${fastify.server.address().port}`
121123

122124
for (const testCase of testCases) {
123-
await t.test(testCase.name, async (t) => {
125+
await t.test(testCase.name, async (/** @type {TestContext} */ t) => {
124126
t.plan(1)
125127

126128
const result = await fetch(`${BASE_URL}${testCase.url}`, {
@@ -133,7 +135,7 @@ test('accept header', async t => {
133135
}
134136
})
135137

136-
test('no reply decorator', async function (t) {
138+
test('no reply decorator', async function (/** @type {TestContext} */ t) {
137139
const fastify = Fastify()
138140
fastify.register(fastifyAccepts, { decorateReply: false })
139141
await fastify.ready()

0 commit comments

Comments
 (0)