Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wellguimaraes/mocha-snapshots
Snapshot/regression testing for using with Mocha, specially for React+Enzyme users.
https://github.com/wellguimaraes/mocha-snapshots
enzyme mocha react snapshots testing
Last synced: about 1 month ago
JSON representation
Snapshot/regression testing for using with Mocha, specially for React+Enzyme users.
- Host: GitHub
- URL: https://github.com/wellguimaraes/mocha-snapshots
- Owner: wellguimaraes
- License: mit
- Created: 2017-06-09T21:52:25.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-25T08:17:43.000Z (almost 2 years ago)
- Last Synced: 2024-10-03T09:31:03.918Z (about 2 months ago)
- Topics: enzyme, mocha, react, snapshots, testing
- Language: JavaScript
- Homepage:
- Size: 141 KB
- Stars: 52
- Watchers: 2
- Forks: 10
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
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('', () => {
it('should match snapshot', () => {
const wrapper = shallow()
// 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
```