Skip to content

atabel/tape-jsx-equals

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tape-jsx-equals

npm npm

Tape extension to compare React components.

tape-jsx-equals uses react-element-to-jsx-string to compare the component rendered output with the expected output.

Install

$ npm install --save-dev extend-tape
$ npm install --save-dev tape-jsx-equals

How to use

Testing React components is very easy with tape + tape-jsx-equals:

const MyComponent = function ({color}) {
    const className = `box color-${color}`;
    return (
        <div className={className}></div>
    );
};
import {createRenderer} from 'react-addons-test-utils';
import tape from 'tape';
import addAssertions from 'extend-tape';
import jsxEquals from 'tape-jsx-equals';
import MyComponent from '../MyComponent';

// extend tape with jsxEqual assertion:
const test = addAssertions(tape, {jsxEquals});

test('MyComponent is properly rendered', (t) => {
	const renderer = createRenderer();
    renderer.render(<MyComponent color="red" />);
    const result = renderer.getRenderOutput();

	// compare output with the expected result:
    t.jsxEquals(result, <div className="box color-red"></div>);
    t.end();
});

Run tests

$ npm install
$ npm test

About

Test React components with tape

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published