Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sebinsua/test-react-shallow-equal
🐢💨💨💨 Unit test against performance problems.
https://github.com/sebinsua/test-react-shallow-equal
jasmine jest matchers performance react redux render shallow-compare shallow-equal test unit-testing
Last synced: about 2 months ago
JSON representation
🐢💨💨💨 Unit test against performance problems.
- Host: GitHub
- URL: https://github.com/sebinsua/test-react-shallow-equal
- Owner: sebinsua
- Created: 2017-09-12T07:54:10.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-09-25T09:21:29.000Z (over 7 years ago)
- Last Synced: 2024-10-18T08:35:38.976Z (3 months ago)
- Topics: jasmine, jest, matchers, performance, react, redux, render, shallow-compare, shallow-equal, test, unit-testing
- Language: JavaScript
- Homepage:
- Size: 131 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# `test-react-shallow-equal`
> Unit test against inadvertent performance problems.Provides a `toShallowEqual` matcher for `jest` and `jasmine`. This matcher can aid in writing performant code as it allows you to write unit tests which [ensure that `shallowEqual` always returns `true` when the underlying values tested have not changed](https://medium.com/@esamatti/react-js-pure-render-performance-anti-pattern-fb88c101332f).
## Usage
The tests give examples of how to use this to test [`mapStateToProps`](./packages/jest-react-shallow-equal/src/__tests__/mapStateToProps.js), [higher-order components (HOCs)](./packages/jest-react-shallow-equal/src/__tests__/HOC.js) and normal [component renders](./packages/test-react-shallow-equal/src/__tests__/ensureInternalPropsAreShallowEqual.js).
## Install
### Installing `jest` matchers
```sh
npm install --save-dev jest-react-shallow-equal
``````js
import installShallowEqualMatcher from 'jest-react-shallow-equal'installShallowEqualMatcher()
test('should x when y', () => {
// ...
})
```### Installing `jasmine` matchers
```sh
npm install --save-dev jasmine-react-shallow-equal
```The `installShallowEqualMatcher` function must be called within a spec's `beforeEach` or `beforeAll` and must be run before testing code.
```js
import installShallowEqualMatcher from 'jasmine-react-shallow-equal'describe('some suite', () => {
beforeAll(() => installShallowEqualMatcher())it('some test', () => {
// ...
})
})
```