Why does React require jsdom for testing?

When writing tests for React components, you must map them to the DOM in order to make statements about their correctness. For example, if you want to check that a certain class has been added to a node with a certain status, you must make it in the DOM node and then check the DOM node through the regular DOM API.

The fact is, given that React supports the virtual DOM, into which it maps, why can't we just claim on the virtual DOM after rendering the component? It seems to me that this is a very good reason to have something like a virtual DOM.

Did I miss something?

+7
javascript dom unit-testing reactjs jestjs
source share
1 answer

You have not missed anything. We are working to make it better. The virtual parts have always been pretty much part of the React implementation, but have not been subjected to any useful or reliable verification. We have some methods in our test helpers that complete internal search queries, which sometimes avoid the real DOM, but we need more.

+6
source share

All Articles