你如何比较两个组件?

时间:2018-03-24 21:13:25

标签: javascript reactjs unit-testing react-native jest

我有一个像这样定义的函数:

renderItem() => <Text onPress={() => console.log('hi)}>Click</Text>

当我调用此方法时,我想声明返回的值是正确的:

expect(renderItem()).toEqual(<Text onPress={() => console.log('hi)}>Click</Text>)

不幸的是,断言失败并出现此错误:

expect(received).toEqual(expected)

Expected value to equal:

    <Text onPress={[Function onPress]}>Click</Text>

Received:

    <Text onPress={[Function onPress]}>Click</Text>

Difference:

    Compared values have no visual difference.

如何正确测试?

0 个答案:

没有答案