JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 390
  • Score
    100M100P100Q86147F
  • License MIT

JSX assertions for Chai

Package Exports

  • chai-equal-jsx

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (chai-equal-jsx) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

chai-equal-jsx

NPM version Build Status Build Status Downloads

Adds equalJSX and includeJSX methods to chai assertions. Uses Algolia's react-element-to-jsx-string under the hood.

Installation

npm install -D chai-equal-jsx

Setup

import chai from 'chai';
import equalJSX from 'chai-equal-jsx';

chai.use(equalJSX);

Usage

The following tests are all passing:

Expect

class TestComponent extends React.Component {}

// equalJSX
expect(<div />).to.equalJSX(<div />);
expect(<TestComponent />).to.equalJSX(<TestComponent />);

expect(<div />).to.not.equalJSX(<span />);
expect(<TestComponent />).to.not.equalJSX(<span />);

// includeJSX
expect(<div><TestComponent /></div>).to.includeJSX(<TestComponent />);
expect(<div><TestComponent /><span /></div>).to.includeJSX(<span></span>);

expect(<TestComponent />).to.not.includeJSX(<span></span>);
expect(<div><span /><TestComponent /></div>).to.not.includeJSX(<a />);

Should

chai.should();

class TestComponent extends React.Component {}

// equalJSX
(<div />).should.equalJSX(<div />);
(<TestComponent />).should.equalJSX(<TestComponent />);

(<div />).should.not.equalJSX(<span />);
(<TestComponent />).should.not.equalJSX(<span />);

// includeJSX
(<div><TestComponent /></div>).should.includeJSX(<TestComponent />);
(<div><TestComponent /><span /></div>).should.includeJSX(<span></span>);

(<TestComponent />).should.not.includeJSX(<span></span>);
(<div><span /><TestComponent /></div>).should.not.includeJSX(<a />);

See test/index.js for usage in context.