Extend Chai with support for asserting JSX equality & contents.
npm install preact-jsx-chai


Extend Chai with support for asserting JSX equality & contents with support for [Preact] Components.
(Heavily) inspired by [jsx-chai].
---
``js
import { h } from 'preact'; /* @jsx h /
import chai, { expect } from 'chai';
import assertJsx from 'preact-jsx-chai';
chai.use(assertJsx);
// check if two JSX DOMs are deeply equal:
expect(
// check if a given JSX DOM contains the given fragment:
expect(
> Note: in environments like Karma where chai is available as a global,
preact-jsx-chai will automatically register itself on import. Don't worry, though, this plugin is smart enough to avoid registering itself multiple times.
---
$3
There are a few global options available to customize how
preact-jsx-chai asserts over VNodes.
| Name | Type | Default | Description
|-----------------|----------|---------|-------------
|
isJsx | Function | _auto_ | Override the detection of values as being JSX VNodes.
| functions | Boolean | _true_ | If false, props with function values will be omitted from the comparison entirely
| functionNames | Boolean | _true_ | If false, ignores function names and bound state, asserting only that the compared props are functions
##### To set these options:
`js
import { options } from 'preact-jsx-chai';
options.functions = false;// or:
import jsxChai from 'preact-jsx-chai';
jsxChai.options.functions = false;
`
---
$3
Deep, fully rendered equality/inclusion is checked for:
.deep.equal, .eql, .include, and .containShallow, JSX only equality/inclusion is checked for:
.equal, .shallow.include, and .shallow.contain`js
let Outer = ({a}) =>
let Inner = ({a}) => {a}// JSX tests
expect( ).to.be.jsx
expect('Outer').to.not.be.jsx
// Deep equality tests
expect( ).to.deep.equal( )
expect( ).to.deep.equal(
foo/>)
expect( ).to.not.deep.equal( )
expect( ).to.eql( ) // .eql is shorthand for .deep.equal
expect( ).to.not.eql( )// Shallow Equality tests
expect( ).to.equal( )
expect( ).to.not.equal( )
expect( ).to.not.equal(
foo) // is not renderedlet WrappedOuter = ({a}) =>
// Deep includes/contains tests
expect( ).to.include(
foo)
expect( ).to.contain(foo)
expect( ).to.contain( )
expect( ).to.not.include(Bad Div)// Shallow includes/contains tests
expect( ).to.shallow.contain( )
expect( ).to.not.shallow.include(
foo)
``---
[MIT]
[Preact]: https://github.com/developit/preact
[jsx-chai]: https://github.com/bkonkle/jsx-chai
[MIT]: http://choosealicense.com/licenses/mit/