我正在使用酶来测试我的create-react-app
组件,但它不能直观地工作。我是否误解了浅渲染是什么?
import React from "react";
import { Card } from "./Card";
const TestUser = () => {
return (
<div>
<div className="test" />
<div className="wrapper">
<Card />
<Card />
<Card />
</div>
</div>
);
};
export default TestUser;
.test.js
import React from "react";
import TestUser from "./TestUser";
import { shallow } from "enzyme";
import { Card } from "./Card";
it("should render right", () => {
const component = shallow(<TestUser />);
expect(component.find(Card)).to.have.length(3);
});
我希望它应该通过测试,因为它确实有 3 个Card
组件TestUser
但它输出: TypeError: Cannot read property 'have' of undefined
这是如何运作的?