如何测试返回对象和useEffect数组的自定义钩子?

时间:2020-02-19 10:10:45

标签: unit-testing jestjs enzyme react-testing-library

const [merchantServicesList, setMerchantServicesList] = useState([]);
const convertSelectedDataToArr =
    selectedData &&
    Object.keys(selectedData)
        .map(i => selectedData[i])
        .filter(m => m.selected);
const convertSelectedDataToArrId = convertSelectedDataToArr && 
    convertSelectedDataToArr.map(s => s.id);

useEffect(() => {
    const handleData = () => {
        if (convertSelectedDataToArr) {
            saveFunc('1234', convertSelectedDataToArrId);
            setMerchantServicesList([...convertSelectedDataToArr]);
        }
    };
    handleData();
}, [selectedData]);
return merchantServicesList;

0 个答案:

没有答案