JSX React Element assertions for chai. Thin wrapper around react-element-to-jsx-string.
Compare different React elements:
expect(<Component />).jsx.to.equal(<Component />);
expect(<Component />).jsx.to.not.equal(<Component prop={value} />);
expect(<Component />).jsx.to.not.equal(<OtherComponent />);
expect(<Component />).jsx.to.not.equal(<div />);
expect(<Component><div /></Component>).jsx.to.equal(<Component><div /></Component>);
expect(<Component><div /></Component>).jsx.to.not.equal(<Component><span /></Component>);
Check for inclusion of child elements:
expect(<Parent><Child /></Parent>).jsx.to.include(<Child />);
This is a addon plugin for the Chai Assertion Library. Install via npm.
npm install chai-jsx
Use this plugin as you would all other Chai plugins.
var chai = require('chai')
, chaiJsx = require('chai-jsx');
chai.use(chaiJsx);