本文介绍了在玩笑的单位测试角度显示正确的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在NX Angle工作区中编写单元测试.有时会出现这样的错误:

I am writing unit test in NX angular workspace. sometimes it is giving error like this :

(node:15320) 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:117:20)
    at process.target._send (internal/child_process.js:779:17)
    at process.target.send (internal/child_process.js:677:19)
    at reportSuccess (C:\Users\INFINTY\angular\nfx__1-sep\node_modules\jest-runner\node_modules\jest-worker\build\workers\processChild.js:67:11)
(node:15320) 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)
(node:15320) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

它没有显示确切的错误.我知道茉莉花/业力中有一个命令可以强制测试以显示正确的错误,但是我忘记了.谁能帮我,我怎么能在玩笑/柏树中得到确切的错误.

It is not showing the exact error. I know there was a command in jasmine/karma to force test to show correct error, but i forgot it. can anyone please help me, how can i get exact error in jest/cypress.

推荐答案

在我的应用中,只需将HttpClientModule导入测试文件中即可(该组件中使用了HttpClient):

In my app, it was a matter of importing the HttpClientModule into the test file (HttpClient was being used in that component):

import { HttpClientModule } from '@angular/common/http';

describe('AppComponent', () => {
    beforeEach(async () => {
        await TestBed.configureTestingModule({
            imports: [HttpClientModule, RouterTestingModule],
            declarations: [AppComponent],
        }).compileComponents();
    });
});

我正在使用:

  • 角度10.1.4
  • 开玩笑26.6.0
  • 玩笑预设角度8.3.1

这篇关于在玩笑的单位测试角度显示正确的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 21:12