我正在使用Enzyme for React 编写测试。
我的测试非常简单:
import OffCanvasMenu from '../index';
import { Link } from 'react-router';
import expect from 'expect';
import { shallow, mount } from 'enzyme';
import sinon from 'sinon';
import React from 'react';
describe('<OffCanvasMenu />', () => {
it('contains 5 <Link /> components', () => {
const wrapper = shallow(<OffCanvasMenu />);
expect(wrapper.find(<Link />)).to.have.length(5);
});
});
此代码基本上直接取自airbnb/enzyme docs,但返回错误:
FAILED TESTS:
<OffCanvasMenu />
✖ contains 5 <Link /> components
Chrome 52.0.2743 (Mac OS X 10.11.6)
TypeError: Cannot read property 'have' of undefined
我有点不清楚我在做什么与文档不同。非常感谢任何指导。