【问题标题】:Default sample test throwing triggerUncaughtException error默认示例测试抛出 triggerUncaughtException 错误
【发布时间】: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


【解决方案1】:

子组件正在使用 axios 进行 api 调用,但未处理异常。

【讨论】:

    猜你喜欢
    • 2015-10-25
    • 1970-01-01
    • 2019-10-10
    • 2019-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-03
    相关资源
    最近更新 更多