我有一个组件,上面有链接。我想测试链接的文本值。
<Link onClick={() => history.push(`/cars/`)}>
<Typography id= "car-reviews">{carCount()}</Typography>
</Link>测试代码如下,
const wrapper = mount(<AssignedCars />);
const displayLabel = wrapper.find({id:'car-reviews'}).first();
expect(displayLabel.text).toBe('0'); 但是这失败了,carCount()返回0,但我需要知道如何测试排版对象的文本。
发布于 2020-10-22 18:35:40
我相信text是一个函数,您需要调用它才能获得要测试的text值。
即
const wrapper = mount(<AssignedCars />);
const displayLabel = wrapper.find({id:'car-reviews'}).first();
expect(displayLabel.text()).toBe('0'); https://enzymejs.github.io/enzyme/docs/api/ReactWrapper/text.html
https://stackoverflow.com/questions/64487653
复制相似问题