https://github.com/sapegin/expect-react-shallow
JSX assertions with Chai-like API (based on unexpected-react-shallow)
https://github.com/sapegin/expect-react-shallow
Last synced: 10 months ago
JSON representation
JSX assertions with Chai-like API (based on unexpected-react-shallow)
- Host: GitHub
- URL: https://github.com/sapegin/expect-react-shallow
- Owner: sapegin
- License: mit
- Created: 2015-11-12T21:50:17.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-11-21T20:58:07.000Z (about 9 years ago)
- Last Synced: 2024-05-02T00:59:20.446Z (over 1 year ago)
- Language: JavaScript
- Size: 13.7 KB
- Stars: 20
- Watchers: 5
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- Contributing: Contributing.md
- License: License.md
Awesome Lists containing this project
README
# expect-react-shallow
[](http://sapegin.github.io/powered-by-you/)
[](https://travis-ci.org/sapegin/expect-react-shallow)
A [Chai’s](http://chaijs.com) expect like API wrapper for [unexpected-react](https://github.com/bruderstein/unexpected-react). It also accepts JSX instead of ShallowRenderer instance.

## Installation
```shell
npm install --save-dev expect-react-shallow
```
## Usage
```js
import React from 'react';
import { expect } from 'mocha';
import expectReactShallow from 'expect-react-shallow';
class TestComponent extends React.Component {
render() {
return
Hello React!;
}
}
describe('TestComponent', () => {
it('works', () => {
// OK
expectReactShallow()
.to.have.rendered(
Hello React!);
// OK
expectReactShallow()
.to.have.exactly.rendered(
Hello React!);
// Error
expectReactShallow()
.to.have.exactly.rendered(
);
// OK
expectReactShallow()
.to.contain(
);
});
});
```
## API
```js
expectReactShallow(ReactComponent|JSX).to.have.rendered(ReactComponent|JSX);
expectReactShallow(ReactComponent|JSX).to.have.rendered.with.all.children(ReactComponent|JSX);
expectReactShallow(ReactComponent|JSX).to.have.exactly.rendered(ReactComponent|JSX);
expectReactShallow(ReactComponent|JSX).to.contain(ReactComponent|JSX);
expectReactShallow(ReactComponent|JSX).to.contain.exactly(ReactComponent|JSX);
expectReactShallow(ReactComponent|JSX).to.contain.with.all.children(ReactComponent|JSX);
expectReactShallow(ReactComponent|JSX).to.not.contain(ReactComponent|JSX);
expectReactShallow(ReactComponent|JSX).to.not.contain.exactly(ReactComponent|JSX);
expectReactShallow(ReactComponent|JSX).to.not.contain.with.all.children(ReactComponent|JSX);
```
See details in [unexpected-react docs](https://github.com/bruderstein/unexpected-react#assertions).
## Changelog
The changelog can be found on the [Releases page](https://github.com/sapegin/expect-react-shallow/releases).
## Contributing
Everyone is welcome to contribute. Please take a moment to review the [contributing guidelines](Contributing.md).
## Author
* [Artem Sapegin](http://sapegin.me)
---
## License
The MIT License, see the included [License.md](License.md) file.