tape-jsx-extensions
v1.0.0
Published
Colection of tape assertion to work with JSX
Downloads
3
Maintainers
Readme
tape-jsx-extensions
Tape extensions collection to make React component easier to test.
Install
$ npm install --save-dev extend-tape
$ npm install --save-dev tape-jsx-extensions
How to use
Testing React components is very easy with tape
+ tape-jsx-extensions
:
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 jsxExtensions from 'tape-jsx-extensions';
import MyComponent from '../MyComponent';
// extend tape with jsx extensions:
const test = addAssertions(tape, jsxExtensions);
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();
});
Assert methods
Run tests
$ npm install
$ npm test