question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

When some static key doesn't match, Object matcher fails all keys that should match to regexp

See original GitHub issue

🐛 Bug Report

When some static key doesn’t match, Object matcher fails all keys that should match to regexp

To Reproduce

Run the following test:

test("asdf", async () => {
  const actual = {
    a: "a_value",
    b: "b_value", 
    c: "c_value"
  }
  expect(actual).toMatchObject({
    a: expect.stringMatching("[a-z]_value"), 
    b: "b_value", 
  })

  expect(actual).toMatchObject({
    a: expect.stringMatching("[a-z]_value"), 
    b: "B_VALUE", 
  })
})

Actual behavior

Matcher reports keys ‘a’ and ‘b’ as mismatched:

Expected value to match object:
  {"a": StringMatching /[a-z]_value/, "b": "B_VALUE"}
Received:
  {"a": "a_value", "b": "b_value", "c": "c_value"}
Difference:
- Expected
+ Received

  Object {
-   "a": StringMatching /[a-z]_value/,
-   "b": "B_VALUE",
+   "a": "a_value",
+   "b": "b_value",
  }

image

Expected behavior

Only ‘b’ key is reported as failed:

   Object {
    -   "b": "B_VALUE",
    +   "b": "b_value",

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
4ekkicommented, Nov 13, 2018

This one is quite annoying since it’s hiding real problems in the output.

0reactions
github-actions[bot]commented, May 12, 2021

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

RegExp - JavaScript - MDN Web Docs - Mozilla
Chrome Edge RegExp Full support. Chrome1. Toggle history Full support. Edge12. Toggle history @@match Full support. Chrome50. Toggle history Full support. Edge13. Toggle history @@matchAll Full...
Read more >
4. Pattern Matching with Regular Expressions - Java ... - O'Reilly
You can then select Match, Find, or Find All. Match means that the entire string must match the regex, and Find means the...
Read more >
Regex Pattern to Match, Excluding when... / Except between
Let's start with some background. First off, this is an excellent question. There are often questions about matching certain patterns except in certain...
Read more >
Python Regex: re.search() VS re.findall() - GeeksforGeeks
re.search() method either returns None (if the pattern doesn't match), or a re.MatchObject that contains information about the matching part ...
Read more >
Argument Validation — Mockery Docs 1.0-alpha documentation
Such argument matching is done on a “best fit” basis. ... By using Hamcrest, Mockery does not need to duplicate Hamcrest's already impressive...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found