# Component testing [Unit testing your Redux actions and reducers](unit-testing.md) is nice, but you can do even more to make sure nothing breaks your application. Since React is the _view_ layer of your app, let's see how to test Components too! - [Shallow rendering](#shallow-rendering) - [Enzyme](#enzyme) ## Shallow rendering React provides us with a nice add-on called the Shallow Renderer. This renderer will render a React component **one level deep**. Lets take a look at what that means with a simple ` ); } export default Button; ``` _Note: This is a [state**less** ("dumb") component](../js/README.md#architecture-components-and-containers)_ It might be used in another component like this: ```javascript // HomePage.react.js import Button from './Button.react'; class HomePage extends React.Component { render() { return( ); } } ``` _Note: This is a [state**ful** ("smart") component](../js/README.md#architecture-components-and-containers)!_ When rendered normally with the standard `ReactDOM.render` function, this will be the HTML output (*Comments added in parallel to compare structures in HTML from JSX source*): ```html ``` Conversely, when rendered with the shallow renderer, we'll get a String containing this "HTML": ```html ``` If we test our `Button` with the normal renderer and there's a problem with the `CheckmarkIcon` then the test for the `Button` will fail as well... but finding the culprit will be hard. Using the _shallow_ renderer, we isolate the problem's cause since we don't render any other components other than the one we're testing! The problem with the shallow renderer is that all assertions have to be done manually, and you cannot do anything that needs the DOM. Thankfully, [AirBnB](https://twitter.com/AirbnbEng) has open sourced their wrapper around the React shallow renderer and jsdom, called `enzyme`. `enzyme` is a testing utility that gives us a nice assertion/traversal/manipulation API. ## Enzyme Lets test our ` ); expect( renderedComponent.find("button").node ).toExist(); }); ``` Nice! If somebody breaks our button component by having it render an `` tag or something else we'll immediately know! Let's do something a bit more advanced now, and check that our ` ); expect( renderedComponent.contains(text) ).toEqual(true); }); ``` Great! Onwards to our last and most advanced test: checking that our `