Change in _owner causes issues with shallow rendered tests
See original GitHub issueThere appears to have been a change in how _owner
is generated between 0.13 and 0.14 which is causing a number of our shallow rendered tests to fail when upgrading because the deepEquals fails on the _owner
property. Here is a simple example component which exhibits the issue.
'use strict';
fdescribe('ComponentTest', function() {
it('passes in 0.13 but fails in 0.14', function() {
var components = {};
components.tester = React.createClass({
getInitialState: function() {
return this.generateState();
},
generateState: function() {
var state = {};
state.body = (
<ul className="foo">
<li><div>Item 1</div></li>
<li>Item 2</li>
</ul>);
return state;
},
render: function() {
return (
<div className="foo">
{this.state.body}
</div>);
}
});
var shallowRenderer = testUtils.createRenderer();
shallowRenderer.render(<components.tester />);
var output = shallowRenderer.getRenderOutput();
assert.deepEqual(output,
<div className="foo">
<ul className="foo">
<li><div>Item 1</div></li>
<li>Item 2</li>
</ul>
</div>);
});
});
AssertionError: expected { '$typeof': 60103,
type: 'div',
key: null,
ref: null,
props:
{ className: 'foo',
children:
{ '$typeof': 60103,
type: 'ul',
key: null,
ref: null,
props: [Object],
_owner: [Object],
_store: {} } },
_owner: null,
_store: {} } to deeply equal { '$typeof': 60103,
type: 'div',
key: null,
ref: null,
props:
{ className: 'foo',
children:
{ '$typeof': 60103,
type: 'ul',
key: null,
ref: null,
props: [Object],
_owner: null,
_store: {} } },
_owner: null,
_store: {} }
Issue Analytics
- State:
- Created 8 years ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
Why I Always Use Shallow Rendering | HackerNoon
The first reason — it's slow. Not actually “just” slow, but “unpredictable” slow. mount renders just everything. There is no limits. When you ......
Read more >In Defense of Shallow Rendering - JavaScript in Plain English
Shallow rendering lets you render a component “one level deep” and assert facts about what its render method returns, without worrying about the...
Read more >The Dangers of Shallow Rendering - Mark Skelton
Three reasons why you should avoid shallow rendering when writing JavaScript component tests. Sign reading “danger no entry”.
Read more >Why I Never Use Shallow Rendering - Kent C. Dodds
The reason this kind of test fails those considerations is because it's testing irrelevant implementation details. The user doesn't care one bit ...
Read more >How to shallow test a non redux connected component that ...
I've had problems working with shallow rendering with enzyme. Currently, enzyme does not support react hooks fully in shallow rendered test ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This should be fixed by #6362.
I prefer applying a monkey patch, until we have this fixed in react by wrapping TestUtils in my own module:
https://gist.github.com/vfil/81049b1590aa3b9e439188a49a5d67bc