Skip to content

lwkchan/custom-jest-matchers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Custom Jest Matchers

Setup

First, make sure that you have the correct peer dependencies installed.

To integrate with your tests, currently, you will need copy from the matcher and set it by adding a setupFilesAfterEnv in jest.config.js. Then, you'll need to extend expect by using expect.extend in that afterEnv file.

See how this is done in this by looking at our jest.config.js and afterEnv.ts.

Rules

.toContainReactElement

Finds a matching React element in a shallow render

it('finds React elements', () => {
  expect(<button type="button">Test</button>).toContainReactElement('button');
});

The second argument can be used to specify props.

it('finds React elements with correct props', () => {
  expect(<button type="button">Test</button>).toContainReactElement('button', {
    type: 'button',
  });
});

To do

  • Set up on NPM registry
  • Add more rules

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published