jest-to-render-without-error
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

jest-to-render-without-error

CircleCI codecov Greenkeeper badge Npm

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.

Readme

Keywords

none

Package Sidebar

Install

npm i jest-to-render-without-error

Weekly Downloads

1

Version

0.2.0

License

MIT

Unpacked Size

8.01 kB

Total Files

9

Last publish

Collaborators

  • dean177