Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enzyme testing: mount vs render

Tags:

reactjs

enzyme

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?

like image 439
artin Avatar asked Jul 04 '16 07:07

artin


People also ask

What is Mount in Enzyme?

The Mount method in Enzyme renders the full DOM, including the parent component's child component on which we are running the tests. It tests the life cycle methods of your React application, allowing testing the state, props, and everything else that makes the lifecycle of a React application.

How do you test a component did mount an Enzyme?

What to do when you want to test that a function is been called, on componentDidMount() React lifecycle Method. Basically the component code looks like this: state = { randomStateToPopulate: [] }; // Test componentDidMount componentDidMount() { this. randomFunction(); } randomFunction= () => { listRandomData().

What is Enzyme shallow render?

Shallow rendering lets you render a component “one level deep” and assert facts about what its render method returns, without worrying about the behavior of child components, which are not instantiated or rendered. This does not require a DOM.

What is test rendering?

Render testing is a periodic load test and calibration of a mooring winch brake at a load based on the Equipment Number (EN) assigned to the ship. Why do we render test? When moored, winch brakes and lines are expected to keep the vessel safely alongside.


1 Answers

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

like image 126
stujo Avatar answered Oct 06 '22 10:10

stujo