我有这个代码:
import Icon from "./icon.svg";
it("should have a prop space", () => {
const tree = shallow(
<Button name="button test" space={Icon} />
);
expect(tree.props().space).toEqual(<span>{Icon} </span>);
});
当我运行它时,我将此作为答案:
期望值等于:
<span>test-file-stub </span>
收到:
<span>test-file-stub </span>
区别: 比较值没有视觉差异。
我错过了什么?
最佳答案
我为预期和接收到的 Prop 编写了 JSON.stringify 并收到了这个:
Expected value to equal: "{\"type\":\"span\",\"key\":null,\"ref\":null,\"props\":{\"children\":[\"test-file-stub\",\" \"]},\"_owner\":null,\"_store\":{}}"
Received: "{\"type\":\"span\",\"key\":null,\"ref\":null,\"props\":{\"children\":[\"test-file-stub\",\" \",null]},\"_owner\":null,\"_store\":{}}"
关于reactjs - 测试组件的 Prop 时,比较值没有视觉差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53300204/