jest-react-renderer
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

jest-react-renderer

Write Jest tests using JSX and React, render them in the DOM and on the CLI. Test as you write your React components in the browser.

yarn add jest-react-renderer

Example:

// sum.test.js
import React from 'react';
import { Test, Expect, runTest } from 'jest-react-renderer';
 
runTest(
  <Test name="adds 1 + 2 to equal 3">
    <Expect toBe={3}>{ sum(1, 2) }</Expect>
  </Test>
);

Create a test file not tracked by Jest:

import { Test, Expect } from 'jest-react-renderer';
import { sum } from './sum';
 
export const MyTestFile = () => (
  <Test name="adds 1 + 2 to equal 3">
    <Expect toBe={3}>{ sum(1, 2) }</Expect>
  </Test>
);

Then add them to jest from a file.test.js.

import { runTests } from 'jest-react-renderer';
import { MyTestFile } from './my-test-file';

runTests([
  <MyTestFile />
]);

This can be dropped straight into something like Storybook to have your tests alongside your documentation and examples.

Internally this uses the expect library from Jest, so you can extend is using expect.extend() for other extensions.

Readme

Keywords

none

Package Sidebar

Install

npm i jest-react-renderer

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

12.9 MB

Total Files

622

Last publish

Collaborators

  • stephenwf