[GH-ISSUE #2242] [bug]: test code can't use the "toHaveProperty" function - it does not exist #770

Open
opened 2026-03-16 17:08:05 +03:00 by kerem · 8 comments
Owner

Originally created by @pantchox on GitHub (Apr 7, 2022).
Original GitHub issue: https://github.com/hoppscotch/hoppscotch/issues/2242

Originally assigned to: @aitchnyu on GitHub.

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

When I write

pw.test("Check JSON response property", ()=> {
    pw.expect(pw.response.body).toHaveProperty("error");
});

the error indicator shows and hovering says 'Unknown Property' (which is ironic..)

The docs show usage of this method/function and I need to validate in the test that specific property exists or not.

What am i missing?

Using PWA installed from "cloud"

Steps to reproduce

write this code in the test:

pw.test("Check JSON response property", ()=> {
    pw.expect(pw.response.body).toHaveProperty("error");
});

Environment

Production

Version

Cloud

Originally created by @pantchox on GitHub (Apr 7, 2022). Original GitHub issue: https://github.com/hoppscotch/hoppscotch/issues/2242 Originally assigned to: @aitchnyu on GitHub. ### Is there an existing issue for this? - [X] I have searched the existing issues ### Current behavior When I write ``` pw.test("Check JSON response property", ()=> { pw.expect(pw.response.body).toHaveProperty("error"); }); ``` the error indicator shows and hovering says 'Unknown Property' (which is ironic..) The docs show usage of this method/function and I need to validate in the test that specific property exists or not. What am i missing? Using PWA installed from "cloud" ### Steps to reproduce write this code in the test: ``` pw.test("Check JSON response property", ()=> { pw.expect(pw.response.body).toHaveProperty("error"); }); ``` ### Environment Production ### Version Cloud
Author
Owner

@pantchox commented on GitHub (Apr 7, 2022):

https://docs.hoppscotch.io/quickstart/tests#response - link for the example using it

<!-- gh-comment-id:1091142065 --> @pantchox commented on GitHub (Apr 7, 2022): https://docs.hoppscotch.io/quickstart/tests#response - link for the example using it
Author
Owner

@pantchox commented on GitHub (Apr 7, 2022):

image

<!-- gh-comment-id:1091142731 --> @pantchox commented on GitHub (Apr 7, 2022): ![image](https://user-images.githubusercontent.com/7011604/162137449-d628fe8c-06d2-47f5-ac23-e4db39194ea8.png)
Author
Owner

@aitchnyu commented on GitHub (Oct 12, 2022):

@liyasthomas Seems .toHaveProperty is not implemented in codebase and confirmed by @AndrewBastin . There are defunct tests in postwomanTesting.sample and there is a section about this in docs. Seems we should delete that section from docs to reflect existing scripting api and plan imlementing .toHaveProperty ins the sandbox revamp.

<!-- gh-comment-id:1276255994 --> @aitchnyu commented on GitHub (Oct 12, 2022): @liyasthomas Seems `.toHaveProperty` is not implemented in codebase and confirmed by @AndrewBastin . There are defunct tests in `postwomanTesting.sample` and there is [a section](https://docs.hoppscotch.io/quickstart/tests#tohavepropertyattribute) about this in docs. Seems we should delete that section from docs to reflect existing scripting api and plan imlementing `.toHaveProperty` ins the [sandbox revamp](https://github.com/hoppscotch/hoppscotch/pull/2735).
Author
Owner

@AndrewBastin commented on GitHub (Oct 22, 2022):

@liyasthomas reminder to update the docs.

<!-- gh-comment-id:1287805622 --> @AndrewBastin commented on GitHub (Oct 22, 2022): @liyasthomas reminder to update the docs.
Author
Owner

@BirnadinErick commented on GitHub (Nov 11, 2022):

is toHaveProperty still not implemented?

<!-- gh-comment-id:1311826574 --> @BirnadinErick commented on GitHub (Nov 11, 2022): is toHaveProperty still not implemented?
Author
Owner

@anthonyaxenov commented on GitHub (Dec 12, 2022):

This is not a bug in fact. I met same problem and quickly found this simple workaround:

pw.test("Check tokens", ()=> {
  pw.expect(pw.response.body.hasOwnProperty('access_token')).toBe(true);
  pw.expect(pw.response.body.hasOwnProperty('refresh_token')).toBe(true);
  //...
});

I think the current test API is simple and good enough so far as you can still use basic js as usual and you are not limited by this API only. Maybe I'm wrong just because today is the first day I try to migrate from Postman but I already have good experience here.

At least it is necessary to replace the last screenshot here - https://docs.hoppscotch.io/quickstart/tests#assert-response-payload. Or implement .toHaveProperty() which I bet was and/or will be just a kinda wrapper of my example above.

<!-- gh-comment-id:1346000811 --> @anthonyaxenov commented on GitHub (Dec 12, 2022): This is not a bug in fact. I met same problem and quickly found this simple workaround: ```javascript pw.test("Check tokens", ()=> { pw.expect(pw.response.body.hasOwnProperty('access_token')).toBe(true); pw.expect(pw.response.body.hasOwnProperty('refresh_token')).toBe(true); //... }); ``` I think the current [test API](https://docs.hoppscotch.io/quickstart/tests) is simple and good enough so far as you can still use basic js as usual and you are not limited by this API only. Maybe I'm wrong just because today is the first day I try to migrate from Postman but I already have good experience here. At least it is necessary to replace the last screenshot here - https://docs.hoppscotch.io/quickstart/tests#assert-response-payload. Or implement `.toHaveProperty()` which I bet was and/or will be just a kinda wrapper of my example above.
Author
Owner

@AndrewBastin commented on GitHub (Dec 12, 2022):

@anthonyaxenov I know it is a bit difficult but we are keeping the current APIs frozen as we are revamping the current scripting section to be a lot more capable. We have an RFC open for the Scripting revamp which we would love everyone's feedback on (see #2292). This will take a bit of time to get implemented but we think it is well worth the effort to push scripting features a lot more.

<!-- gh-comment-id:1347053347 --> @AndrewBastin commented on GitHub (Dec 12, 2022): @anthonyaxenov I know it is a bit difficult but we are keeping the current APIs frozen as we are revamping the current scripting section to be a lot more capable. We have an RFC open for the Scripting revamp which we would love everyone's feedback on (see #2292). This will take a bit of time to get implemented but we think it is well worth the effort to push scripting features a lot more.
Author
Owner

@ChindrisSebilix commented on GitHub (Aug 6, 2024):

@AndrewBastin not sure if you need the reminder, but .toHaveProperty is still not implemented/removed from docs

<!-- gh-comment-id:2270997209 --> @ChindrisSebilix commented on GitHub (Aug 6, 2024): @AndrewBastin not sure if you need the reminder, but `.toHaveProperty` is still not implemented/removed from docs
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hoppscotch#770
No description provided.