Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/smacker/jasmine-expect-jsx
Adds `toEqualJSX` method to jasmine and jest assertions
https://github.com/smacker/jasmine-expect-jsx
jasmine jest jsx react
Last synced: about 1 month ago
JSON representation
Adds `toEqualJSX` method to jasmine and jest assertions
- Host: GitHub
- URL: https://github.com/smacker/jasmine-expect-jsx
- Owner: smacker
- Created: 2015-12-08T05:25:29.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2020-05-13T04:11:18.000Z (over 4 years ago)
- Last Synced: 2024-11-02T09:32:09.793Z (about 2 months ago)
- Topics: jasmine, jest, jsx, react
- Language: JavaScript
- Homepage:
- Size: 2.92 MB
- Stars: 9
- Watchers: 3
- Forks: 5
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# jasmine-expect-jsx [![npm](https://img.shields.io/npm/v/jasmine-expect-jsx.svg?maxAge=2592000)](https://www.npmjs.com/package/jasmine-expect-jsx) [![Build Status](https://api.travis-ci.org/smacker/jasmine-expect-jsx.svg)](https://travis-ci.org/smacker/jasmine-expect-jsx)
[![Greenkeeper badge](https://badges.greenkeeper.io/smacker/jasmine-expect-jsx.svg)](https://greenkeeper.io/)
Adds `toEqualJSX` and `toIncludeJSX` methods to jasmine assertions.
Uses Algolia's [react-element-to-jsx-string](https://github.com/algolia/react-element-to-jsx-string) under the hood.## Installation
```
npm install -D jasmine-expect-jsx
```## Setup
### Browser
```html
```
### Karma
Integration is easy with the [karma-jasmine-expect-jsx](https://github.com/smacker/karma-jasmine-expect-jsx) plugin and it provides colored output.
Also you can just add `'node_modules/jasmine-expect-jsx/dist/jasmine-expect-jsx.js'` to files section of your config.
### Node.js
```javascript
require('jasmine-expect-jsx');
```### Jest
1. Add `setupTestFrameworkScriptFile` in `package.json`
```json
{
...
"jest": {
"setupTestFrameworkScriptFile": "/jestSetup.js"
}
...
}
```2. Import `jasmine-expect-jsx` in `setupTestFrameworkScriptFile` file
```javascript
// jestSetup.js
require('jasmine-expect-jsx');
```## Usage
The following tests are all passing:
### Expect
```javascript
class TestComponent extends React.Component {}// equalJSX
).toEqualJSX();
expect(
expect().toEqualJSX();expect(
).not.toEqualJSX();
expect().not.toEqualJSX();// includeJSX
expect(Hello World!).toIncludeJSX(Hello World!);
expect().toIncludeJSX(); // assuming is rendered by TestComponent's renderexpect(
Hello World!).not.toIncludeJSX(Hello World!);
expect().not.toIncludeJSX(); // assuming is not rendered by TestComponent's render
```