Node.js 如何有效地排除故障;未处理的PromisejectionWarning:TypeError:将循环结构转换为JSON;错误?

Node.js 如何有效地排除故障;未处理的PromisejectionWarning:TypeError:将循环结构转换为JSON;错误?,node.js,angular,unit-testing,jestjs,Node.js,Angular,Unit Testing,Jestjs,在测试角度组件或服务时,我谈论的是以下错误: UnhandledPromiseRejectionWarning: TypeError: Converting circular structure to JSON --> starting at object with constructor 'Object' | property 'element' -> object with constructor 'Object' | property '

在测试角度组件或服务时,我谈论的是以下错误:

UnhandledPromiseRejectionWarning: TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Object'
    |     property 'element' -> object with constructor 'Object'
    |     property 'componentProvider' -> object with constructor 'Object'
    --- property 'parent' closes the circle
    at stringify (<anonymous>)
    at writeChannelMessage (internal/child_process/serialization.js:118:20)
    at process.target._send (internal/child_process.js:779:17)
    at process.target.send (internal/child_process.js:677:19)
    at reportSuccess (/home/user/code/my-app/node_modules/jest-runner/node_modules/jest-worker/build/workers/processChild.js:67:11)
(node:4658) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
UnhandledPromisejectionWarning:TypeError:将循环结构转换为JSON
-->从构造函数为“object”的对象开始
|属性'element'->构造函数为'object'的对象
|属性“componentProvider”->具有构造函数“object”的对象
---属性“parent”关闭该圆
在stringify()
在writeChannelMessage(internal/child_process/serialization.js:118:20)
at process.target.\u send(internal/child\u process.js:779:17)
在process.target.send(内部/child_process.js:677:19)
在reportSuccess(/home/user/code/my app/node_modules/jest runner/node_modules/jest worker/build/workers/processChild.js:67:11)
(节点:4658)未处理的PromisejectionWarning:未处理的承诺拒绝。此错误源于在没有catch块的异步函数中抛出,或者拒绝未使用.catch()处理的承诺。要在未处理的承诺拒绝时终止节点进程,请使用CLI标志“---unhandled rejections=strict”(请参阅https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (拒绝id:1)
当我忘记在测试期间运行的服务上模拟异步方法时,这些情况通常会发生在我身上。有时很容易找到,因为组件/服务很小,但有时很难找到,因为有太多地方可能发生这种情况


如何有效地排除此类错误并找出其原因?跟踪没有任何用处,并且完全没有告诉我要在哪里查找。

可能的未处理的Rejection listener副本就足够了。但其他时候,这很难,因为有太多的地方可能会发生这种情况-你没有足够的模拟可能是真正的问题,模拟除了测试单元以外的任何东西。独立的单元测试有助于隔离问题。@EstusFlask:该问题的解决方案是添加
process.on('unhandledRejection',console.error)到jestSetup文件。在我的问题中,有这样的设置就是产生信息和跟踪的原因。