Socket
Book a DemoInstallSign in
Socket

tape-jsx-equals

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tape-jsx-equals

tape assertion to compare react components

latest
npmnpm
Version
1.0.0
Version published
Weekly downloads
36
2.86%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

test

FAQs

Package last updated on 19 Oct 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts