ππΌββ Dive deepοΈ
yarn add enzyme-dive --dev
import * as Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-xx';
import configure from "enzyme-dive";
Enzyme.configure({ adapter: new Adapter() });
// The magic π§πΌββοΈ
configure(Enzyme.ShallowWrapper);
Use this to dive until you reach your component. This can be useful if you've got many HoC wrappers.
import React from 'react';
import { shallow } from "enzyme";
import Component from './Component';
import ChildComponent from './ChildComponent';
describe('<Component />', function() {
it("should render child", () => {
const wrapper = shallow(<Component />).diveTo(ChildComponent);
expect(wrapper).toMatchSnapshot();
});
});
Dive through your nodes a specified amount
import React from 'react';
import { shallow } from "enzyme";
import Component from './Component';
describe('<Component />', function() {
it("should render", () => {
// const wrapper = shallow(<Component />).dive().dive().dive().dive().dive();
const wrapper = shallow(<Component />).diveDeep(5);
expect(wrapper).toMatchSnapshot();
});
});