Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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
expect(

).toEqualJSX(
);
expect().toEqualJSX();

expect(

).not.toEqualJSX();
expect().not.toEqualJSX();

// includeJSX
expect(

Hello World!
).toIncludeJSX(Hello World!);
expect().toIncludeJSX(); // assuming is rendered by TestComponent's render

expect(

Hello World!
).not.toIncludeJSX(Hello World!);
expect().not.toIncludeJSX(); // assuming is not rendered by TestComponent's render
```