我有一个看起来像这样的组件
const Devices = ({
devices, selectDevice, selectedDeviceIdList, deleteDevices,
}) => {
<FlatListShadow
shadowColor={Colors.PRIMARY_COLOR}
data={devices}
renderItem={({ item }) => (
<Device
title={item.deviceName}
platform={item.platform}
updatedAt={item.updatedAt}
status={item.status}
selectDevice={() => selectDevice(item.deviceId)}
isSelected={selectedDeviceIdList.includes(item.deviceId)}
/>
)}
keyExtractor={item => item.id}
extraData={[devices, selectedDeviceIdList]}
/>
}
我正在尝试编写代码以测试isSelected = {selectedDeviceIdList.includes(item.deviceId)}
所以我首先做一个浅包装纸
shallow(
<Devices
selectedDeviceIdList={[]}
devices={multipleDevicesArry}
selectDevice={selectDevice}
deleteDevices={deleteDevices}
/>,
)
然后我拉出renderItem函数并创建一个数组来保存所有isSelected值
const RenderItem = wrapper.find(FlatListShadow).prop('renderItem')
const deviceListValues = []
devices.forEach(device => {
deviceListValues.push(shallow(<RenderItem item={device} />))
})
问题是,似乎无法找到selectedDeviceIdList,并且isSelected值全部为假