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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
4ekki opened this issue Aug 31, 2018 · 8 comments

Comments

@4ekki
Copy link

4ekki commented Aug 31, 2018

馃悰 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",
@4ekki
Copy link
Author

4ekki commented Nov 13, 2018

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

@garyking
Copy link

garyking commented Nov 14, 2018

Any workaround for this for now? Just test individual object paths instead of the whole thing with toMatchObject, I guess?

@thymikee
Copy link
Collaborator

@pedrottimark is this on your roadmap to improve error messages of core matchers?

@4ekki
Copy link
Author

4ekki commented Jan 14, 2019

Any update regarding this issue?

@dandv
Copy link
Contributor

dandv commented Jan 27, 2019

Have been seeing this issue for a few months; still there in v24.

@jeysal
Copy link
Contributor

jeysal commented Jan 27, 2019

Unfortunately, this is all but trivial to fix, see #7027 (comment)
I believe this should be marked as duplicate of #6184?

@SimenB
Copy link
Member

SimenB commented Jan 27, 2019

Yeah, duplicate of #6184

@SimenB SimenB closed this as completed Jan 27, 2019
@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants