-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error when using server.inject(): "Cannot read private member #strategies from an object whose class did not declare it" #4119
Comments
This may be related to #4013 According to https://2ality.com/2019/07/private-class-fields.html#this-and-private-static-fields when extending a class, the sub-class cannot access the super-class's private fields with |
I will admit this is a confusing one, but I see what is going on here and it is technically known/expected behavior. The trouble-maker isn't hapi: it's actually lab. Lab's I would guess that before hapi used private fields, using a clone of the hapi server wouldn't cause any issues, but I don't use this feature so I am unsure. It might be worth filing an issue in lab to see if there's a way we can account for this use case in the future. Here's a diff demonstrating how to get it working again: const { it, describe, before } = (exports.lab = Lab.script());
describe("GET /", () => {
- before(async ({ context }) => {
+ const context = {};
+
+ before(async () => {
context.server = await getServer();
await context.server.initialize();
});
- it("responds with 401 when no credentials provided", async ({ context }) => {
+ it("responds with 401 when no credentials provided", async () => {
const res = await context.server.inject({
method: "GET",
url: `/some-path`, |
@devinivy a bit unrelated by I believe Hapi using private fields internally so this would be something to keep in mind: https://twitter.com/jasnell/status/1276297531798896641
|
Thanks @devinivy! I filed this over on lab's issue tracker so I'll close this issue and keep future discussion over there. |
Support plan
Context
14.3.0
&12.18.2
19.2.0
18.4.1
node
@hapi/lab
andserver.inject()
What are you trying to achieve or the steps to reproduce?
I am trying to write
@hapi/lab
integration tests with the latest version of hapi and lab. If I use any authentication strategy, the tests fail withCannot read private member #strategies from an object whose class did not declare it
The routes still work fine when accessed via an actual HTTP request. Also, it doesn't seem matter what strategy was used - I encountered the issue with
hapi-auth-jwt2
but reproduced with the latest version of@hapi/basic
as well.I am running
lab
withlab tests
from the npmtest
script. Minimal reproduction is available at chrisshiplet/hapi-inject-bug-repro and below:tests/get-some-path.js
get-server.js
package.json
What was the result you got?
What result did you expect?
The tests should run successfully.
The text was updated successfully, but these errors were encountered: