【发布时间】:2021-12-31 00:26:59
【问题描述】:
全新项目抛出以下错误
PASS client/src/App.test.js
node:internal/process/promises:246
triggerUncaughtException(err, true /* fromPromise */);
^
[UnhandledPromiseRejection: 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(). The promise rejected with the re
ason "Error: Network Error".] {
code: 'ERR_UNHANDLED_REJECTION'
}
它说它仍然是PASS,但是为什么会抛出这个异常?
下面是我的 app.test.js 文件
/**
* @jest-environment jsdom
*/
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom'
import React from 'react';
import App from './App';
test('renders product list', () => {
render(<App />);
const linkElement = screen.getByText(/Products/i);
expect(linkElement).toBeInTheDocument();
});
【问题讨论】:
-
原来一个子组件在没有 .catch(error.... 的情况下进行 axios 调用
标签: reactjs jestjs babel-jest