artin
artin

Reputation: 1834

Enzyme testing: mount vs render

Besides render uses "traversal library Cheerio"..

I've just replaced all my mount's with render's and it works the same.
They look similar to me.

What should I choose? Is API of those two is somehow not identical?
What are particular recommendations when to use render over mount?

Upvotes: 8

Views: 7357

Answers (2)

stujo
stujo

Reputation: 2109

Render doesn't need a global DOM to be available. So it allows the tests to be run outside of an environment like a browser. In your case, if your test cases were working before it would seem you are running the tests in a browser (since mount worked) and you wouldn't need to use render. If however, your tests were failing because there was no global DOM available, then render might be a good solution

http://airbnb.io/enzyme/docs/api/render.html

Upvotes: 5

Sidharth Mehra
Sidharth Mehra

Reputation: 1

Mount is FullDom rendering. Take a look at the official documentation for examples. From my understanding if you want to test lifecycle events such as componentDidMount you should use mount.

Docs: http://airbnb.io/enzyme/docs/api/mount.html

Upvotes: 0

Related Questions