React Answers

How to check the actual DOM node using React enzyme?

Spread the love

To check the actual DOM node using React enzyme, we use the findDOMNode and wrapper.instance methods.

For instance, we write

import ReactDOM from "react-dom";


const wrapper = mount(<input type="text" defaultValue="sup" />);
console.log(ReactDOM.findDOMNode(wrapper.instance()) === wrapper.instance());

to mount the input component with mount.

Then we call ReactDOM.findDOMNode with wrapper.instance() to find the DOM node for the instance.

And we check that against wrapper.instance() to see if it returns the same DOM node.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *