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

Match object recursively (toMatchObject) #2506

Closed
ismay opened this issue Jan 5, 2017 · 6 comments
Closed

Match object recursively (toMatchObject) #2506

ismay opened this issue Jan 5, 2017 · 6 comments

Comments

@ismay
Copy link

ismay commented Jan 5, 2017

The discussion on recursive matching suggested here #1793 (comment) was never continued in the PR. As far as I can tell toMatchObject does not match recursively, but it would be nice if this was a possibility.

@pedrottimark
Copy link
Contributor

@ismay How do these examples adapted from the unit tests for toMatchObject compare to your expectations for recursive matching, pardon the pun :)

describe('toMatchObject', () => {
  it('matches recursively', () => {
    expect({
      a: 'b',
      t: {
        x: {
          r: 'r'
        },
        z: 'z'
      }
    }).toMatchObject({
      t: {
        x: {
          r: 'r'
        }
      }
    });
    expect({
      a: 'b',
      t: {
        x: {
          r: 'r'
        },
        z: 'z'
      }
    }).not.toMatchObject({
      t: {
        l: {
          r: 'r'
        }
      }
    });
  });
});

@ismay
Copy link
Author

ismay commented Jan 5, 2017

Maybe I should have worded it differently, but what I mean is it matching:

x: {
  r: 'r'
}

In the test you mentioned, even though that's nested under t. To me that would be useful when testing if an object needs to contain something but you don't care about where exactly.

@thymikee
Copy link
Collaborator

@ismay are you willing to ship a PR on that?

@ismay
Copy link
Author

ismay commented Jan 14, 2017

Definitely willing, but no time atm I'm afraid.

@thymikee
Copy link
Collaborator

Cool, take your time, no worries! 🙂

@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 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants