# jsx-for-chai

> JSX assertions for Chai

Latest version **5.0.1** (published 2018-12-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install jsx-for-chai
pnpm add jsx-for-chai
yarn add jsx-for-chai
bun add jsx-for-chai
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.0.1 |
| Published | 2018-12-12 |
| First published | 2018-12-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 253.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Chris Abrams |
| Maintainers | chrisabrams |
| Keywords | chai, testing, assertions, jsx, react |

## Links

- npm: https://www.npmjs.com/package/jsx-for-chai
- Repository: https://github.com/chrisabrams/jsx-for-chai
- Homepage: https://github.com/chrisabrams/jsx-for-chai#readme
- Issues: https://github.com/chrisabrams/jsx-for-chai/issues
- npm.io page: https://npm.io/package/jsx-for-chai

## Dependencies (2)

- [collapse-white-space](https://npm.io/package/collapse-white-space.md) ^1.0.4
- [react-element-to-jsx-string](https://npm.io/package/react-element-to-jsx-string.md) ^14.0.2

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 5.0.1 (latest) — 2018-12-12
- 5.0.0 — 2018-12-12

## README

# JSX for Chai

Fork of [jsx-chai](https://github.com/bkonkle/jsx-chai)

It uses [algolia/react-element-to-jsx-string][react-element-to-jsx-string] in
the background to turn React elements into formatted strings.

## Installation

Then install *jsx-chai*:

    npm install jsx-chai --save-dev

## Assertions

JSX comparison will kick in on deep equality checks, but normal strict equality
will apply when the 'deep' flag is not used.

```javascript
    expect(<Component/>).to.be.jsx
    expect('Component').to.not.be.jsx
    expect(<Component/>).to.deep.equal(<Component/>)
    expect(<Component prop='value'/>).to.not.deep.equal(<Component prop='other-value'/>)
    expect(<Component/>).to.eql(<Component/>)
    expect(<Component prop='value'/>).to.not.eql(<Component otherProp='value'/>)
    expect(<Component><h1>Title</h1></Component>).to.include(<h1>Title</h1>)
    expect(<Component><h1>Title</h1></Component>).to.not.include(<div/>)
```

Note: `include.keys()` calls will look for normal object properties, and will
not use JSX comparison.

## Usage

Here's an example using [mochajs/mocha](https://github.com/mochajs/mocha).

```js
import chai, {expect} from 'chai'
import jsxChai from 'jsx-chai'
import React from 'react'

chai.use(jsxChai)

class TestComponent extends React.Component {}

describe('jsx-chai', () => {

  it('works', () => {
    expect(<div/>).to.deep.equal(<div/>)
    // ok

    expect(<div a="1" b="2"/>).to.deep.equal(<div/>)
    // Error: Expected '<div\n  a="1"\n  b="2"\n/>' to equal '<div />'

    expect(<span/>).to.not.deep.equal(<div/>)
    // ok

    expect(<div><TestComponent/></div>).to.include(<TestComponent/>)
    // ok
  })

})
```

It looks like this when ran:

![Screenshot when using mocha][screenshot]

## A note about functions

`to.deep.equal` and `to.eql` will not check for function references, it only
checks that if a `function` was expected somewhere, there's also a function in
the actual data.

It's your responsibility to then unit test those functions.

---
_Source: https://npm.io/package/jsx-for-chai · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
