我在 React.js 中有一个简单的 Intro 组件,它呈现一个 h1 和一个 p。
我正在尝试使用 Enzyme 为通过的 h1 & p 字符串编写测试,但我无法做到这一点。这段代码有什么问题?
it('description of element is okay <p>', () => {
const wrapper = shallow(<Intro title="Heading of element" description="Description of element" />);
expect(wrapper.find('p').text().to.contain("Description of element")); // This is not working!
});
如果我控制台记录wrapper.find('p').text()
它不是未定义的......但控制台说这样的:
1) (Component) Intro contains a single <p>:
TypeError: Cannot read property 'contain' of undefined
at Context.<anonymous> (test/components/alerts/alert.spec.js:19:12)