enzyme-shallow-until

enzyme-shallow-until react test util

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
enzyme-shallow-until
1.0.15 years ago5 years agoMinified + gzip package size for enzyme-shallow-until in KB

Readme

enzyme-shallow-until
!Travisbuild-badgebuild !Greenkeepergreenkeeper-badgegreenkeeper !Codecovcodecov-badgecodecov !CodeFactorcodefactor-badgecodefactor !BCH compliancebettercodehub-badgebettercodehub !bitHound ScorebitHound-badgebitHound !Known Vulnerabilitiessnyk-badgesnyk
enzyme-shallow-until is a utility library to extend enzyme's shallow function. It gives ShallowWrapper the ability to dive until a specific component type. Especially useful when you have some HOC-style components to test.

Setup

  • install

npm i -D enzyme enzyme-shallow-until enzyme-adapter-react-xx
  • setup ShallowWrapper
import Enzyme, { shallow } from 'enzyme';
import Adapter from 'enzyme-adapter-react-xx';
import ShallowWrapper from 'enzyme/ShallowWrapper';

Enzyme.configure({ adapter: new Adapter() });
ShallowWrapper.prototype.until = until;

Usage

const wrapper = shallow(<ComposedComponent />).until(Component);

Use with jest snapshot and enzyme-to-json

// in test-setup.js
import { createSerializer } from 'enzyme-to-json';
expect.addSnapshotSerializer(createSerializer({ mode: 'deep' }));

// in xxx.test.js
it('should keep render result unchanged', () => {
  const wrapper = shallow(<ComposedComponent />).until(Component);
  expect(wrapper).toMatchSnapshot();
})

Thanks

Thank @matthieuprat for his gist

License MIT