Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to check the actual DOM node using react enzyme

Tags:

Is there a way to get the actual DOM node so I can the query it with the Dom api as opposed to being required to use enzyme's api, it's just for edge cases where for example I need to assert things about the dom node itself.

like image 963
njorlsaga Avatar asked Jun 09 '16 10:06

njorlsaga


People also ask

How do you get DOM node in react?

In React we can access the DOM element using Refs. Refs provide a way to access DOM nodes or React elements created in the render method. Creating Refs: Refs are created using React. createRef() and attached to React elements via the ref attribute.

How do you read Dom in react?

We access a DOM element using the current property of a reference created with the React. createRef() function. React will update this property with an actual DOM element after render and before update events. That means that we can access the DOM element in componentDidMount and componentDidUpdate functions.

What is getDOMNode?

getDOMNode() => DOMComponent. Returns the outer most DOMComponent of the current wrapper. Notes: can only be called on a wrapper of a single node.


1 Answers

You can use wrapper.getDOMNode()

Enzyme docs

like image 99
tonyjmnz Avatar answered Oct 18 '22 10:10

tonyjmnz