jsx-test-helpers
Version:
Helpers to easily write tests for React component/JSX code
55 lines (35 loc) • 2.08 kB
Markdown
# jsx-test-helpers
[](https://travis-ci.org/MoOx/jsx-test-helpers)
[](https://github.com/MoOx/jsx-test-helpers/blob/master/CHANGELOG.md)
[](https://github.com/MoOx/jsx-test-helpers)
[](https://gitlab.com/MoOx/jsx-test-helpers)
[](https://bitbucket.org/MoOx/jsx-test-helpers)
> Helpers to easily write tests for React component/JSX code
This package [is very small](src/index.js) and provide simple helpers to easily use [React shallow rendering](http://facebook.github.io/react/docs/test-utils.html#shallow-rendering) method in conjunction with [react-element-to-jsx-string](https://github.com/algolia/react-element-to-jsx-string) to write straightforward tests for React component.
**⚠️ [Be sure to read the test file, which is annotated](src/__tests__/index.js) 😙.**
## Installation
```console
$ npm install jsx-test-helpers
```
## Usage
**⚠️ [Be sure to read the test file, which have more complete annotated examples](src/__tests__/index.js).**
Example with [Jest](http://facebook.github.io/jest/):
```js
import React from 'react';
import { noop, renderJSX, JSX } from 'jsx-test-helpers';
import FunctionalComponentToTest from '../your-component';
// fixture
function FakeComponent() {}
test('Can render & test a functional component', () => {
expected(renderJSX(<FunctionalComponentToTest bool />)).toMatch(
JSX(<FakeComponent fixedProp={'some-value'} bool />)
);
});
```
---
## CONTRIBUTING
* ⇄ Pull/Merge requests and ★ Stars are always welcome.
* For bugs and feature requests, please create an issue.
* Pull/Merge requests must be accompanied by passing automated tests (`$ npm test`).
## [CHANGELOG](CHANGELOG.md)
## [LICENSE](LICENSE)