使用Jest和Enzyme进行测试 - 潜水不是一种功能

时间:2017-03-20 22:40:33

标签: reactjs jestjs enzyme

试图从酶中复制dive()示例,但继续获得TypeError: wrapper.find(...).dive is not a function

代码:

class Bar extends React.Component {
  render() {
    return (
      <div>
        <div className="in-bar" />
      </div>
    );
  }
}

class Foo extends React.Component {
  render() {
    return (
      <div>
        <Bar />
      </div>
    );
  }


it('renders correctly', () => {
  const wrapper = shallow(<Foo />);
  expect(wrapper.find('.in-bar').length).toBe(0);
  expect(wrapper.find(Bar).length).toBe(1);
  expect(wrapper.find(Bar).dive().find('.in-bar').length).toBe(1);
});

1 个答案:

答案 0 :(得分:0)