Shallow rendering is a method used while testing React components in which the component is "one level deep". Such a shallow-rendered test component has the facts regarding the returned things with respect to the render
methods. Such components do not have the child components attached to it, and it does not require DOM.
Thus, while testing with a shallow rendering method, it should be remembered that any changes in the parent component that has the DOM changes and/or any child components been changed may require in rewriting the test.
Let's explore this with help of some code. In the following example, we will be creating a React component (GreetingComponent
) where the render
method will return a div
with two children (h2
and span
elements).
The code of greeting.js
:
// greeting.js import React from 'react'; const { div, h2, span} = React.DOM; export default React.createClass({ displayName: 'GreetingComponent', render(){ return( div({classname...