tape-jsx-extensions

1.0.0 • Public • Published

tape-jsx-extensions

npm npm

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

Package Sidebar

Install

npm i tape-jsx-extensions

Weekly Downloads

0

Version

1.0.0

License

MIT

Last publish

Collaborators

  • atabel