jest-to-render-without-error
v0.2.0
Published
A jest matcher to ensure a react component will render
Downloads
15
Readme
jest-to-render-without-error
A Jest matcher to verify the render method of a React component
Installation
jest-to-render-without-error
depends on Enzyme being installed as a peer dependency, please ensure enzyme is configured and available in your test environment.
yarn add jest-to-render-without-error --dev
npm install jest-to-render-without-error --save-dev
In your setupTestEnvironment.js
// src/setupTestEnvironment.js
require('jest-to-render-without-error')
Then in the "jest" section of your package.json add the following:
"setupTestFrameworkScriptFile": "<rootDir>/src/setupTestEnvironment.js"
Usage
expect(<MyCustomComponent propA={'A'} propB={true} />).toRenderWithoutError()
Test environment
jest-to-render-without-error
behaves slightly differently depending on wether a DOM (such as JSDOM) is available at test time.
Without a DOM (the default) only the immediate components render method is tested, any errors or warnings in child components will not be reported.
Motivation
This matcher provides an easy way to ensure that the render method of your component will not cause any errors or warnings to be logged and returns without causing an exception.
This provides a lot of confidence that refactoring elsewhere in your codebase hasn't unintentionally broken your components.