[GH-ISSUE #3590] [bug]: Written tests on payload #1235

Closed
opened 2026-03-16 19:26:49 +03:00 by kerem · 3 comments
Owner

Originally created by @IeuanWalker on GitHub (Nov 23, 2023).
Original GitHub issue: https://github.com/hoppscotch/hoppscotch/issues/3590

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

Trying to write a test to make sure an array from the payload includes a specific value -
image

But the test just errors -
image

Steps to reproduce

pw.test("Check JSON response property", ()=> {
	const result = pw.response.body.data;
  	var isWest = result.combinedResults.includes("West");

    pw.expect(isWest).toBe(true);
});

Environment

Production

Version

Self-hosted

Originally created by @IeuanWalker on GitHub (Nov 23, 2023). Original GitHub issue: https://github.com/hoppscotch/hoppscotch/issues/3590 ### Is there an existing issue for this? - [X] I have searched the existing issues ### Current behavior Trying to write a test to make sure an array from the payload includes a specific value - ![image](https://github.com/hoppscotch/hoppscotch/assets/6544051/b247f9f6-5893-48f4-9b8b-dd4909b0ee4d) But the test just errors - ![image](https://github.com/hoppscotch/hoppscotch/assets/6544051/1352d56d-9672-4497-8032-9a86034f4169) ### Steps to reproduce ```js pw.test("Check JSON response property", ()=> { const result = pw.response.body.data; var isWest = result.combinedResults.includes("West"); pw.expect(isWest).toBe(true); }); ``` ### Environment Production ### Version Self-hosted
kerem 2026-03-16 19:26:49 +03:00
Author
Owner

@liyasthomas commented on GitHub (Nov 24, 2023):

The response doesn't seem to have a data property. Hence you only needed to use pw.response.body. Can you try this code block and see if it works?

// Check response includes "West"
pw.test("Check response includes West", ()=> {
  const result = pw.response.body
  let isWest = result.combinedResults.includes("West")
  pw.expect(isWest).toBe(true);
});
<!-- gh-comment-id:1825154361 --> @liyasthomas commented on GitHub (Nov 24, 2023): The response doesn't seem to have a `data` property. Hence you only needed to use `pw.response.body`. Can you try this code block and see if it works? ```javascript // Check response includes "West" pw.test("Check response includes West", ()=> { const result = pw.response.body let isWest = result.combinedResults.includes("West") pw.expect(isWest).toBe(true); }); ```
Author
Owner

@IeuanWalker commented on GitHub (Nov 24, 2023):

@liyasthomas thanks, that worked.

Might want to update the doc to make that clear - https://docs.hoppscotch.io/documentation/getting-started/rest/tests

<!-- gh-comment-id:1825886184 --> @IeuanWalker commented on GitHub (Nov 24, 2023): @liyasthomas thanks, that worked. Might want to update the doc to make that clear - https://docs.hoppscotch.io/documentation/getting-started/rest/tests
Author
Owner

@liyasthomas commented on GitHub (Nov 25, 2023):

Sorry for the misunderstanding. But the example shown in documentation is correct. The request URL used in the example is;

https://reqres.in/api/users/10

which produces a response similar to;

{
  "data": {
    "id": 10,
    "email": "byron.fields@reqres.in",
    "first_name": "Byron",
    "last_name": "Fields",
    "avatar": "https://reqres.in/img/faces/10-image.jpg"
  },
  "support": {
    "url": "https://reqres.in/#support-heading",
    "text": "To keep ReqRes free, contributions towards server costs are appreciated!"
  }
}

Hence the example test script will work.

<!-- gh-comment-id:1826196341 --> @liyasthomas commented on GitHub (Nov 25, 2023): Sorry for the misunderstanding. But the example shown in documentation is correct. The request URL used in the example is; ``` https://reqres.in/api/users/10 ``` which produces a response similar to; ``` { "data": { "id": 10, "email": "byron.fields@reqres.in", "first_name": "Byron", "last_name": "Fields", "avatar": "https://reqres.in/img/faces/10-image.jpg" }, "support": { "url": "https://reqres.in/#support-heading", "text": "To keep ReqRes free, contributions towards server costs are appreciated!" } } ``` Hence the example test script will work.
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#1235
No description provided.