请问老师,useState的值如何mock?
来源:2-12 Jest 中的 Mock(2)

鎏金华舞
2021-02-26
写回答
1回答
-
鎏金华舞
提问者
2021-02-26
import React, { useState } from 'react'; import Taro, { useDidShow } from '@tarojs/taro'; import { View, Navigator, Text } from '@tarojs/components'; import './index.less'; export default function Index() { const [bindPhone, setBindPhone] = useState(''); useDidShow(() => { const { bindPhone } = Taro.getStorageSync('person'); setBindPhone(bindPhone); }); return bindPhone ? ( <View className="login-components"> <Navigator className="login-content font-medium" url="/page/registerPack/index"> <View className="login-text">登录 / 注册 </View> </Navigator> </View> ) : null; }
请问,我想测试 bindPhone 有值的情况下渲染这个组件,没有值的情况不渲染。如何去测试mock呢,写了很久,网上没找到好的例子
012021-02-28
相似问题