# mocha-snapshots

> Snapshot testing for Mocha users

Latest version **4.2.0** (published 2019-01-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install mocha-snapshots
pnpm add mocha-snapshots
yarn add mocha-snapshots
bun add mocha-snapshots
```

## 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 | 4.2.0 |
| Published | 2019-01-02 |
| First published | 2017-06-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 60.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 52 |
| Author | Wellington Guimaraes |
| Maintainers | wellguimaraes |
| Keywords | mocha, snapshot, regression, test, testing |

## Links

- npm: https://www.npmjs.com/package/mocha-snapshots
- Repository: https://github.com/wellguimaraes/mocha-snapshots
- Homepage: https://github.com/wellguimaraes/mocha-snapshots#readme
- Issues: https://github.com/wellguimaraes/mocha-snapshots/issues
- npm.io page: https://npm.io/package/mocha-snapshots

## Dependencies (3)

- [diff](https://npm.io/package/diff.md) ^3.5.0
- [colors](https://npm.io/package/colors.md) ^1.3.3
- [enzyme-to-json](https://npm.io/package/enzyme-to-json.md) ^3.3.5

## 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
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 4.2.0 (latest) — 2019-01-02
- 4.1.0 — 2018-05-05
- 4.0.0 — 2018-01-27
- 3.0.0 — 2017-10-20
- 2.4.1 — 2017-06-12
- 2.4.0 — 2017-06-12
- 2.3.2 — 2017-06-12
- 2.3.1 — 2017-06-12
- 2.3.0 — 2017-06-12
- 2.2.2 — 2017-06-12
- 2.2.1 — 2017-06-12
- 2.2.0 — 2017-06-12
- 2.1.1 — 2017-06-12
- 2.1.0 — 2017-06-12
- 2.0.0 — 2017-06-12
- … 7 more at https://npm.io/package/mocha-snapshots/versions

## README

# Mocha Snapshots
Snapshot/regression testing for using with Mocha, specially for React+Enzyme users.

## Install it
`npm i mocha-snapshots --save`

## Use it
```es6
import { expect } from 'chai';
import { shallow } from 'enzyme';
import MyComponent from './path/to/MyComponent';

describe('<MyComponent />', () => {
  it('should match snapshot', () => {
    const wrapper = shallow(<MyComponent />)
    
    // You can match Enzyme wrappers
    expect(wrapper).to.matchSnapshot();
    
    // Strings
    expect('you can match strings').to.matchSnapshot();
    
    // Numbers
    expect(123).to.matchSnapshot();
    
    // Or any object
    expect({ a: 1, b: { c: 1 } }).to.matchSnapshot();
   
  });
});
```

## Run your tests
Add a require argument to your test script/command 

`mocha --require mocha-snapshots`

## Disable classNames cleanup
To prevent false mismatches, mocha-snapshots sanitizes className props by default. You can disable this behavior before running your tests:
```js
import mochaSnapshots from 'mocha-snapshots';

mochaSnapshots.setup({ sanitizeClassNames: false })
```

## Update snapshots
Set an environment variable `UPDATE` and run your test script or add the flag `--update`  when running Mocha:

```
UPDATE=1 mocha --require mocha-snapshots
``` 
or
```
mocha --require mocha-snapshots --update
```

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