Skip to content

sebinsua/test-react-shallow-equal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

21 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

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.

Usage

The tests give examples of how to use this to test mapStateToProps, higher-order components (HOCs) and normal component renders.

Install

Installing jest matchers

npm install --save-dev jest-react-shallow-equal
import installShallowEqualMatcher from 'jest-react-shallow-equal'

installShallowEqualMatcher()

test('should x when y', () => {
  // ...
})

Installing jasmine matchers

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.

import installShallowEqualMatcher from 'jasmine-react-shallow-equal'

describe('some suite', () => {
  beforeAll(() => installShallowEqualMatcher())

  it('some test', () => {
    // ...
  })
})