你好我是新的测试Hooks,所以我真的很迷茫,试图找到答案但没有结果。
所以问题是,我如何useEffect
从这段代码中进行测试?
代码:
const [ range, setRange ] = useState(DATE_OPTIONS.LAST_30_DAYS)
const [ isLoading, setIsLoading ] = useState(true)
const startLoading = () => setIsLoading(true)
const stopLoading = () => setIsLoading(false)
useEffect(() => {
startLoading()
fetchYearlyOptiDrive(range, objectId)
.then(stopLoading)
.catch(stopLoading)
}, [range, objectId])
我想从代码中测试的是LoadingIndicator
,检查道具isLoading
,如果是true
or false
。
<LoadingIndicator {...{ isLoading }} />
测试:
test('should return the default value', () => {
const wrapper = mount(<OptiDriveCard {...props} />)
expect(wrapper.find('LoadingIndicator').props).toBeTruthy()
})
错误:
不变违规:元素类型无效:预期为字符串(对于内置组件)或类/函数(对于复合组件)但得到:未定义
有什么建议吗?