# enzyme-redux

> Test utils to simplify testing of containers in redux with enzyme.

Latest version **0.2.1** (published 2018-03-18) · 0 weekly downloads

## Install

```sh
npm install enzyme-redux
pnpm add enzyme-redux
yarn add enzyme-redux
bun add enzyme-redux
```

## Health

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

Positive: has types package; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.1 |
| Published | 2018-03-18 |
| First published | 2016-07-14 |
| Weekly downloads | 0 |
| TypeScript types | separate (@types/enzyme-redux) |
| Module format | CommonJS |
| Node | >=6 |
| Dependencies | 0 |
| Unpacked size | 7.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 48 |
| Author | Dennis Axelsson |
| Maintainers | knegusen |
| Keywords | redux, enzyme, store, test |

## Links

- npm: https://www.npmjs.com/package/enzyme-redux
- Repository: https://github.com/Knegusen/enzyme-redux
- Homepage: https://github.com/Knegusen/enzyme-redux#readme
- Issues: https://github.com/Knegusen/enzyme-redux/issues
- npm.io page: https://npm.io/package/enzyme-redux

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads
- [aws-elasticsearch-connector](https://npm.io/package/aws-elasticsearch-connector.md) — 37.4K weekly downloads

## Recent versions

- 0.2.1 (latest) — 2018-03-18
- 0.2.0 — 2018-03-13
- 0.1.8 — 2018-03-06
- 0.1.7 — 2017-09-28
- 0.1.6 — 2016-07-14
- 0.1.5 — 2016-07-14
- 0.1.4 — 2016-07-14
- 0.1.3 — 2016-07-14
- 0.1.2 — 2016-07-14
- 0.1.1 — 2016-07-14
- 0.1.0 — 2016-07-14

## README

# enzyme-redux [![Build Status](https://travis-ci.org/knegusen/enzyme-redux.svg?branch=master)](https://travis-ci.org/knegusen/enzyme-redux)

Test utils to simplify testing of containers in redux with enzyme.

## Install

In the terminal execute the following command:

```
$ npm install enzyme-redux --save-dev
```

## How to use

### shallowWithStore

```js

import React from 'react';
import { connect } from 'react-redux';
import { shallowWithStore } from 'enzyme-redux';
import { createMockStore } from 'redux-test-utils';

describe('example shallowWithStore', () => {
  const ReactComponent = () => (<div>dummy component</div>);
  describe('state', () => {
    it('works', () => {
      const expectedState = 'expectedState';
      const mapStateToProps = (state) => ({
        state,
      });
      const ConnectedComponent = connect(mapStateToProps)(ReactComponent);
      const component = shallowWithStore(<ConnectedComponent />, createMockStore(expectedState));
      expect(component.props().state).toBe(expectedState);
    });
  });
  
  describe('dispatch', () => {
    it('works', () => {
      const action = {
        type: 'type',
      };
      const mapDispatchToProps = (dispatch) => ({
        dispatchProp() {
          dispatch(action);
        },
      });
      const store = createMockStore();

      const ConnectedComponent = connect(undefined, mapDispatchToProps)(ReactComponent);
      const component = shallowWithStore(<ConnectedComponent />, store);
      component.props().dispatchProp();
      expect(store.isActionDispatched(action)).toBe(true);
    });
  });
});

```

### shallowWithState

```js

import React from 'react';
import { connect } from 'react-redux';
import { shallowWithState } from 'enzyme-redux';

describe('example shallowWithState', () => {
  const ReactComponent = () => (<div>dummy component</div>);
  it('works', () => {
    const expectedState = 'expectedState';
    const mapStateToProps = (state) => ({
      state,
    });
    const ConnectedComponent = connect(mapStateToProps)(ReactComponent);
    const component = shallowWithState(<ConnectedComponent />, expectedState);
    expect(component.props().state).toBe(expectedState);
  });
});

```


### mountWithStore

```js

import React from 'react';
import { connect } from 'react-redux';
import { mountWithStore } from 'enzyme-redux';
import { createMockStore } from 'redux-test-utils';

describe('example mountWithStore', () => {
  const ReactComponent = () => (<div>dummy component</div>);
  describe('state', () => {
    it('works', () => {
      const expectedState = 'expectedState';
      const mapStateToProps = (state) => ({
        state,
      });
      const ConnectedComponent = connect(mapStateToProps)(ReactComponent);
      const component = mountWithStore(<ConnectedComponent />, createMockStore(expectedState));
      expect(component.props().state).toBe(expectedState);
    });
  });
  
  describe('dispatch', () => {
    it('works', () => {
      const action = {
        type: 'type',
      };
      const mapDispatchToProps = (dispatch) => ({
        dispatchProp() {
          dispatch(action);
        },
      });
      const store = createMockStore();

      const ConnectedComponent = connect(undefined, mapDispatchToProps)(ReactComponent);
      const component = mountWithStore(<ConnectedComponent />, store);
      component.props().dispatchProp();
      expect(store.isActionDispatched(action)).toBe(true);
    });
  });
});

```

### mountWithState

```js

import React from 'react';
import { connect } from 'react-redux';
import { mountWithState } from 'enzyme-redux';

describe('example mountWithState', () => {
  const ReactComponent = () => (<div>dummy component</div>);
  it('works', () => {
    const expectedState = 'expectedState';
    const mapStateToProps = (state) => ({
      state,
    });
    const ConnectedComponent = connect(mapStateToProps)(ReactComponent);
    const component = mountWithState(<ConnectedComponent />, expectedState);
    expect(component.props().state).toBe(expectedState);
  });
});

```

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