Skip to content
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

Regex inside expectJsonMatchStrict does not work as expected #25

Closed
prateekbstack opened this issue Jan 24, 2024 · 0 comments · Fixed by #26
Closed

Regex inside expectJsonMatchStrict does not work as expected #25

prateekbstack opened this issue Jan 24, 2024 · 0 comments · Fixed by #26
Assignees
Labels
bug Something isn't working

Comments

@prateekbstack
Copy link

prateekbstack commented Jan 24, 2024

Describe the bug

I have to validate a json which has a format like below

{
  "browsers": [
    {
      "platform": "linux",
      "browser": "chrome",
      "browser_version": "120.0",
      "release": "stable",
      "release_tag": "latest"
    },
    {
      "platform": "linux",
      "browser": "chrome",
      "browser_version": "119.0",
      "release": "stable",
      "release_tag": "latest-1"
    },
    {
      "platform": "linux",
      "browser": "chrome",
      "browser_version": "118.0",
      "release": "stable",
      "release_tag": "latest-2"
    }
  ]
}

My validation code snippet is:

.expectJsonMatchStrict({
  'browsers': eachLike({
    'platform': string(),
    'browser': regex(/(chrome|firefox|msedge)/),
    'browser_version': string(),
    'release': string(),
    'release_tag': regex(/latest+|null/)
  })
})

This throws Json doesn't match with "(chrome|firefox|msedge)" at "$.browsers[0].browser" but found "regex"
This is weird, because if I use /(chrome|firefox)/ then it correctly breaks at $.browsers[20].browser, where there is an instance of msedge, outside the scope of expected regex.
Not sure why it's breaking at index 0 in my original regex, where chrome is present.

@ASaiAnudeep ASaiAnudeep added the bug Something isn't working label Jan 31, 2024
@ASaiAnudeep ASaiAnudeep transferred this issue from pactumjs/pactum Mar 31, 2024
@ASaiAnudeep ASaiAnudeep self-assigned this Mar 31, 2024
@ASaiAnudeep ASaiAnudeep linked a pull request Mar 31, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants