docs(hooks): document this binding for preClose hook and strengthen test assertion#6738
Open
harihara-ai wants to merge 1 commit into
Open
docs(hooks): document this binding for preClose hook and strengthen test assertion#6738harihara-ai wants to merge 1 commit into
harihara-ai wants to merge 1 commit into
Conversation
…est assertion Add sentence documenting that hook functions are invoked with `this` bound to the Fastify instance in the preClose section of docs/Reference/Hooks.md. Also convert the callback example from arrow function to regular function to avoid misleading readers into thinking arrow functions work here. Strengthen test/close.test.js assertions from a weak typeof check to t.assert.strictEqual(this.pluginName, fastify.pluginName) — matching the existing pattern in test/hooks.on-ready.test.js. Fixes fastify#4967
Member
|
Based on the username, plus the commit comment, this smells like a bot. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does
Documents the
thisbinding for thepreClosehook indocs/Reference/Hooks.md, and strengthens the corresponding test assertions intest/close.test.js.Problem
The
preClosesection in the docs did not state that hook functions receive athisbinding. Its callback-style code example used an arrow function, which would breakthisbinding if copied literally. Both neighbouring sections (onReady,onListen) already documented this and used thefunctionkeyword.The two
preClosetests usedt.assert.ok(typeof this === typeof fastify)— a weak type-equality check that passes even whenthisis bound to the wrong object, as long as both are objects.Changes
docs/Reference/Hooks.md—preClosesection:thisbound to the associated Fastify instance."functionkeywordtest/close.test.js—preClose callbackandpreClose asynctests:t.assert.ok(typeof this === typeof fastify)witht.assert.strictEqual(this.pluginName, fastify.pluginName, 'the this binding is the right instance')test/hooks.on-ready.test.jsTesting
node --test test/close.test.js→ 22/22 pass, exit code 0. No logic changes; no API changes.Closes #4967