TestUtils.renderIntoDocument doesn't function as expected in all browsers
See original GitHub issueHi,
Here is my program (jsfiddle):
var Input = React.createClass({
render: function() {
return (
<input
{...this.props}
/>
);
}
});
var TestUtils = React.addons.TestUtils;
var inputInstance =
TestUtils.renderIntoDocument(
<Input
value='abc'
/>
);
var inputDOMNode = React.findDOMNode(inputInstance);
inputDOMNode.focus();
// Place cursor at the end.
inputDOMNode.setSelectionRange(3, 3);
// Should log 3 twice.
console.log(inputDOMNode.selectionStart);
console.log(inputDOMNode.selectionEnd);
Problem: 0
is logged twice in Chrome and Firefox.
What I expected: 3
is logged twice. We see this in Safari.
The interesting part is if we use React.render(..., document.body)
instead of TestUtils.renderIntoDocument
the program works as expected.
I am using:
- Chrome 42.0.2311.135
- Firefox 37.0.2
- Safari 8.0.5 (10600.5.17)
Issue Analytics
- State:
- Created 8 years ago
- Comments:11 (2 by maintainers)
Top Results From Across the Web
Test with reactjs renderIntoDocument keep failed due to ...
tl;dr; You need jsdom + Mocha . According to spec ReactTestUtils#renderIntoDocument ,. renderIntoDocument() requires a DOM: You will need to have window, ...
Read more >Test Utilities - React
renderIntoDocument () Render a React element into a detached DOM node in the document. This function requires a DOM.
Read more >Day 2: Testing React Applications - 12 Devs of Xmas
I've written the entire application in ES2015 using Babel. I've installed all our dependencies through npm as Node modules and webpack converts ...
Read more >unexpected-react
Checking a simple render. var todoList = TestUtils.renderIntoDocument( ; Triggering an event on a button inside a subcomponent (using the eventTarget prop to ......
Read more >Testing and Performance - Piazza
SWE 432, Fall 2016. Design and Implementation of Software for the Web ... For interaction with DOM/browser. ... Only write code if it's...
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 is definitely a problem for accessibility testing. We need components to be attached to test them fully, as the current method makes the tree appear to be hidden. It would be really helpful to have blessed methods for doing this, as appending to the body and then removing messes up my other tests with “The DOM was unexpectedly mutated” errors.
@marcysutton Thanks, that’s useful feedback. If you do need to append to the document then the most straightforward and flexible solution is to call ReactDOM.render manually:
That’s also exactly what the implementation of any test helper we might provide would do.