This package has been deprecated

Author message:

Use @commercetools/jest-enzyme-matchers instead

jest-enzyme-matchers

1.0.0 • Public • Published

jest-enzyme-matchers

Enzyme specific jest matchers

Installation

  1. Add package

npm install jest-enzyme-matchers --save-dev

  1. Add testFrameworkScriptFile

Set up a setupTestFrameworkScriptFile. Create that file and add it to the jest configuration.

  1. Add matchers to Jest

In that testFrameworkScriptFile file, import the matchers and add them to jest

import * as enzymeMatchers from 'jest-enzyme-matchers'
 
expect.extend(enzymeMatchers)
 
// more expect.extend calls for your own matcheres
// expect.extend({ /* ... */ })

Usage

toRender(selector)

Passes when at least one element matching the selector is found in the wrapper.

import Icon from 'somewhere'
 
describe('Component', () => {
  const wrapper = shallow(<Component />)
  it('should render an Icon', () => {
    expect(wrapper).toRender(Icon)
  })
  it('should render a Button', () => {
    expect(wrapper).toRender('Button')
  })
})

toRenderElementTimes(selector, times)

Passes when the number of elements matching the selector found in the wrapper matches times exactly.

import Icon from 'somewhere'
 
describe('Component', () => {
  const wrapper = shallow(<Component />)
  it('should render one Icon', () => {
    expect(wrapper).toRenderElementTimes(Icon, 1)
  })
  it('should render two Buttons', () => {
    expect(wrapper).toRenderElementTimes('Button', 2)
  })
})

Readme

Keywords

none

Package Sidebar

Install

npm i jest-enzyme-matchers

Weekly Downloads

0

Version

1.0.0

License

MIT

Last publish

Collaborators

  • dferber90
  • emmenko
  • philippspo