我需要测试catch获取数据请求何时被拒绝,但我不明白为什么错误没有被捕获,并且出现此错误:
UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
我有这样的情况:
export const Container = ({fetchFirstAsset, fetchSecondAsset}) => {
const [status, setStatus] = useState(null);
async function fetchAssets() {
setStatus(IN_PROGRESS);
try {
await fetchFirstAsset();
await fetchSecondAsset()
setStatus(SUCCESS);
} catch {
setStatus(FAILURE);
}
}
useEffect(() => {
fetchAssets();
}, []);
....
};
Run Code Online (Sandbox Code Playgroud)
我这样测试:
import {mount} from …Run Code Online (Sandbox Code Playgroud)