【发布时间】:2018-11-16 09:32:38
【问题描述】:
我正在尝试进行一个开玩笑的单元测试,它只是确认 refreshControl 道具在我的 ScrollView 中处于活动状态。
我目前有一个组件,它基本上呈现以下内容
<ScrollView
refreshControl={
<RefreshControl
refreshing={this.state.refreshing}
onRefresh={this._onRefresh}
/>
}
{children}
/>
它在实践中运行良好,在我的测试中,我正在检查以确认道具是否符合预期。
import { RefreshControl } from 'react-native'
const layout = shallow(<Element />)
const refreshControl = <RefreshControl
onRefresh={jest.fn()}
refreshing={false}
/>
expect(layout.prop('refreshControl')).toEqual(refreshControl)
然后我在运行测试时收到此错误:
Expected value to equal:
<RefreshControlMock onRefresh={[Function mockConstructor]} refreshing={false} />
Received:
<RefreshControlMock onRefresh={[Function mockConstructor]} refreshing={false} />
我认为这是因为 onRefresh 函数的实例不同,但不确定如何控制它。有人知道吗?
【问题讨论】:
标签: react-native jestjs