[GH-ISSUE #2221] [feature]: Add expect().toInclude([string]) method #765

Closed
opened 2026-03-16 17:04:39 +03:00 by kerem · 1 comment
Owner

Originally created by @ace-n on GitHub (Apr 1, 2022).
Original GitHub issue: https://github.com/hoppscotch/hoppscotch/issues/2221

Originally assigned to: @ace-n on GitHub.

Is there an existing issue for this?

  • I have searched the existing issues

Summary

Add a toInclude() method to pw.expect()

(toContain() could work too, but JS itself uses includes(), not contains().)

Why should this be worked on?

I want to assert that an unstructured page contains a certain string of text.

(For example, I want to assert that /attractions?q=egypt should contain Pyramids of Giza)

Current workaround

Currently, you can do the following:

pw.expect(pw.response.body.includes("example")).toBe(true)

This is suboptimal for two reasons:

  1. It doesn't produce a detailed assertion message.
  2. It's a bit verbose. 🙂

Contribution notes

I'm happy to take a first-pass at an implementation myself, if a maintainer is OK with it! 😄

Originally created by @ace-n on GitHub (Apr 1, 2022). Original GitHub issue: https://github.com/hoppscotch/hoppscotch/issues/2221 Originally assigned to: @ace-n on GitHub. ### Is there an existing issue for this? - [X] I have searched the existing issues ### Summary Add a `toInclude()` method to `pw.expect()` (`toContain()` could work too, but [JS itself](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes) uses `includes()`, not `contains()`.) ### Why should this be worked on? I want to assert that an unstructured page contains a certain string of text. (For example, I want to assert that `/attractions?q=egypt` should contain `Pyramids of Giza`) ### Current workaround Currently, you can do the following: ``` pw.expect(pw.response.body.includes("example")).toBe(true) ``` This is suboptimal for two reasons: 1) It doesn't produce a detailed assertion message. 2) It's a bit verbose. 🙂 ### Contribution notes I'm happy to take a first-pass at an implementation myself, if a maintainer is OK with it! 😄
kerem 2026-03-16 17:04:39 +03:00
  • closed this issue
  • added the
    feature
    label
Author
Owner

@liyasthomas commented on GitHub (Apr 1, 2022):

Hi @ace-n, feel free to pick up this feature request. Do let us know if you've any trouble understanding the source code. Assigning this to you.

<!-- gh-comment-id:1085380697 --> @liyasthomas commented on GitHub (Apr 1, 2022): Hi @ace-n, feel free to pick up this feature request. Do let us know if you've any trouble understanding the source code. Assigning this to you.
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#765
No description provided.