React 测试 Typography Text Enzyme
React test the Typography Text Enzyme
我有一个组件上面有 link。我想测试 link.
的文本值
<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,但我需要知道如何测试 Typography 对象的文本。
我相信 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
我有一个组件上面有 link。我想测试 link.
的文本值 <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,但我需要知道如何测试 Typography 对象的文本。
我相信 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