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.

shallow.get() returns ReactElement with wrong type

See original GitHub issue

Current behavior

Grabbing a connected component by using shallow().get(0) returns a ReactElement with the wrong type (type: function ConnectionFunction() instead of type: Object).

Looks like this issue did not arise in enzyme-adapter-react-16 1.12.1 (setting the adapter version to 1.12.1 in the sandbox makes the test pass), but subsequent versions do have this issue.

Expected behavior

Should return a ReactElement with type: Object.

Your environment

https://codesandbox.io/s/happy-sammet-6o3li

API

  • shallow
  • mount
  • render

Version

library version
enzyme 3.10.0 (latest as of writing)
react 16.8.6 (latest stable as of writing)
react-dom 16.8.6 (latest stable as of writing)
react-test-renderer (not a direct dependency)
adapter (below) 1.14.0 (latest as of writing)

Adapter

  • enzyme-adapter-react-16
  • enzyme-adapter-react-16.3
  • enzyme-adapter-react-16.2
  • enzyme-adapter-react-16.1
  • enzyme-adapter-react-15
  • enzyme-adapter-react-15.4
  • enzyme-adapter-react-14
  • enzyme-adapter-react-13
  • enzyme-adapter-react-helper
  • others ( )

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Joonpark13commented, Jun 18, 2019

That one seems to work. It’s gonna be a real hefty change in our codebase to change our usages of .toEqual or .toEqualJSX to matchesElement, but if we’re not using shallow as intended, that just might be the way we have to go. Thanks!

0reactions
ljharbcommented, Jun 17, 2019

I also wouldn’t rely on that - enzyme has matchesElement, what happens if you expect(component.matchesElement(<Child />)).toBe(true)?

Read more comments on GitHub >

github_iconTop Results From Across the Web

shallow.get() returns ReactElement with wrong type #2168
Current behavior Grabbing a connected component by using shallow().get(0) returns a ReactElement with the wrong type (type: function ...
Read more >
How to test style for a React component attribute with Enzyme
It returns ReactElement. let containerStyle = container.get(0).style; expect(containerStyle).to.have.property('opacity', '1');.
Read more >
React Top-Level API
Return a function that produces React elements of a given type. Like React.createElement() , the type argument can be either a tag name...
Read more >
Why I Never Use Shallow Rendering
This is a very common misconception: "To unit test a react component you must use shallow rendering so other components are not rendered."...
Read more >
Understanding common frustrations with React Hooks
What was wrong with class components? ... async componentDidMount() { const response = await get(`/users`); this.
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