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

3.4.x breaks existing test involving returning an array of items #1749

Closed
meganwalker-ibm opened this issue Aug 13, 2018 · 2 comments
Closed

Comments

@meganwalker-ibm
Copy link

meganwalker-ibm commented Aug 13, 2018

Describe the bug

Previously, when using 3.3.x the code and test outlined in the reproduction steps would pass. Now in 3.4.x it does not. It is unclear if this is a case of our code / test being wrong, or if enzyme has accidentally regressed something whilst trying to land React 16 features.

Several of our tests, are failing now, but I've isolated down one of them to the most minimal recreate possible - stripping out all props and ensuring it still acts as we've observed.

To Reproduce
Steps to reproduce the behavior:

Here's a minimal test case for the simplest of the tests that are now failing...
Create a react component like so:

const Minimal = () => {
  return []
}

export default Minimal

Create a jest test like so:

describe('Minimal', () => {

  describe('minmal tests', () => {
    it('works', () => {
      const wrapper = shallow(<Minimal />)
      expect(wrapper).toHaveLength(1)
      expect(wrapper.find('div')).toHaveLength(0)
    })
  })
})

Test this out against
[email protected]
[email protected]
[email protected]

flipping between [email protected] and [email protected]

Expected behavior
A clear and concise description of what you expected to happen.
In 3.3.x, this test case passed. Wrapper had length 1, and wrapper.find(div) had length 0.
In 3.4.x the expect statement expect(wrapper).toHaveLength(1) fails with length 0.

Additional context

[email protected] (previously 3.4.0)
[email protected]
[email protected]
[email protected]

If you need any more information, let me know. I can't see anything obviously wrong with our code (the re-create is minimal, but we need to check the logic based on a large combination of props -> which, for this has boiled down to the recreate above once you strip out the logic).

@ljharb
Copy link
Member

ljharb commented Aug 13, 2018

This was a bug in < 3.4; and components rendering arrays is still not fully supported in enzyme (see #1213).

In this case, a component that returns an empty array is basically identical to one returning null - both don’t actually render anything. It was incorrect for enzyme to ever return a length of 1 there.

@meganwalker-ibm
Copy link
Author

Ahh, I see. Thanks for clarifying! With that information I've managed to work out why our other cases were broken too. Feel free to close it out :)

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