Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access actual rendered HTML created by dangerouslySetInnerHTML in Enzyme tests

My component renders HTML using dangerouslySetInnerHTML property. I need to access this rendered HTML in my enzyme tests. How can I do that?

I already tried component.html() but it returns something like <button ...>[object Object]</button>.

like image 659
Marek Takac Avatar asked Jan 16 '18 09:01

Marek Takac


1 Answers

You can access it via the component props ...

const { dangerouslySetInnerHTML: { __html } } = component.props();

console.log('__html', __html);
like image 181
dcodesmith Avatar answered Oct 27 '22 01:10

dcodesmith