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

toMatchElement does not allow matching only some fields #241

Open
brennancheung opened this issue Jun 19, 2018 · 1 comment
Open

toMatchElement does not allow matching only some fields #241

brennancheung opened this issue Jun 19, 2018 · 1 comment

Comments

@brennancheung
Copy link

brennancheung commented Jun 19, 2018

I see there is a closed issue #163. It works around the issue but it does not look like it fully solves problem. I'm opening this one to be more specific and provide a test case that wrongly fails.

Enzyme's matchesElement only matches the props that the user supplies. If there are additional props that aren't specified in the match it still passes.

However, toMatchElement functions differently. It requires that ALL props match. This is extremely inconvenient and often impractical to specify all the other props.

Here's an example the failing behavior:

it('jest-enyzme bug', () => {
  const wrapper = shallow(
    <form>
      <input
        type="text"
        id="description"
        placeholder="additonal prop for negative testing"
      />
    </form>
  )
  const input = wrapper.find('input')

  // Passes when the given subset of props match
  expect(input.matchesElement(<input id="description" />)).toEqual(true)

  // Detects when one of the props does not match
  expect(input.matchesElement(<input id="noMatch" />)).toEqual(false)

  // This test should NOT fail.  enzyme-matchers does not function the same.
  // It wrongly requires ALL the props to match.
  expect(input).toMatchElement(<input id="description" />, { ignoreProps: false })
})
@blainekasten
Copy link
Collaborator

sounds like a bug, interested in diving in and contributing a fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants