Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

911
Views
UnhandledPromiseRejectionWarning: TypeError: Conversión de estructura circular a JSON con Jest + Angular

Usando jest-preset-angular para realizar la prueba unitaria, pero recibió una advertencia como UnhandledPromiseRejectionWarning: TypeError: Converting circular structure to JSON no estoy seguro de qué está causando el error, debido a esto, la aplicación está atascada y no está ejecutando la otra prueba unitaria.

 PASS src/app/pages/result/result-filter/result-filter.component.spec.ts (6.251 s) PASS src/app/pages/result/search-navigation/search-navigation.component.spec.ts PASS src/app/pages/result/filter-modal/filter-modal.component.spec.ts (5.699 s) PASS src/app/app.component.spec.ts PASS src/app/pages/test-type/test-type.component.spec.ts (12.857 s) (node:3280) 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:808:17) at process.target.send (internal/child_process.js:706:19) at reportSuccess (/Users/macbook/Projects/Playtime Projects/IDP/Idp.Bx.Ui/idp/node_modules/jest-worker/build/workers/processChild.js:67:11) (Use `node --trace-warnings ...` to show where the warning was created) (node:3280) 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:3280) [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. (node:3281) 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:808:17) at process.target.send (internal/child_process.js:706:19) at reportSuccess (/Users/macbook/Projects/Playtime Projects/IDP/Idp.Bx.Ui/idp/node_modules/jest-worker/build/workers/processChild.js:67:11) (Use `node --trace-warnings ...` to show where the warning was created) (node:3281) 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:3281) [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. (node:3279) 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:808:17) at process.target.send (internal/child_process.js:706:19) at reportSuccess (/Users/macbook/Projects/Playtime Projects/IDP/Idp.Bx.Ui/idp/node_modules/jest-worker/build/workers/processChild.js:67:11) (Use `node --trace-warnings ...` to show where the warning was created) (node:3279) 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:3279) [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. RUNS src/app/pages/location/location.component.spec.ts RUNS src/app/pages/signup/signup.component.spec.ts RUNS src/app/pages/login/login.component.spec.ts Test Suites: 10 passed, 10 of 20 total Tests: 16 passed, 16 total Snapshots: 1 obsolete, 5 passed, 5 total Time: 2180 s

No estoy seguro de cómo ejecutar el nodo --trace-warnings. Parece que es un problema de serialización, incluso es solo una advertencia, pero no estoy seguro de dónde está el problema. ¿Hay alguna manera mejor de encontrar la excepción?

over 4 years ago · Santiago Trujillo
7 answers
Answer question

0

Parece que el error se debe a que se está realizando alguna operación asíncrona. Intente envolver su prueba unitaria dentro de una función waitForAsync.

over 4 years ago · Santiago Trujillo Report

0

El problema fue con la operación asíncrona, así que al escribir el caso de prueba a continuación, resuelva el problema por mí

describe('DateSelectionComponent', () => { let component: DateSelectionComponent; let fixture: ComponentFixture<DateSelectionComponent>; beforeEach(async(() => { TestBed.configureTestingModule({ declarations: [DateSelectionComponent, SafePipe], imports: [ SharedModule, NgReduxTestingModule, RouterTestingModule.withRoutes([]) ], providers: [ { provide: PageAPIActions, useValue: { setPageState() { } } } ] }).compileComponents(); fixture = TestBed.createComponent(DateSelectionComponent); component = fixture.componentInstance; // Don't use Object.defineProperty when assigning value to class properties component.page$ = of('value'); component.page = { destination: 'value' }; component.startDate = new NgbDate(2019, 2, 27); component.minDate = new NgbDate(2019, 2, 27); fixture.detectChanges(); })); it('should create', () => { expect(component).toBeTruthy(); }); it('Should Match Snapshot', () => { expect(fixture.debugElement.nativeElement).toMatchSnapshot() }); });
over 4 years ago · Santiago Trujillo Report

0

Agregar mi respuesta para ayudar a alguien si se pierde. En mi caso me ha faltado importar

 import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

Capaz de encontrar el problema solo cuando se ejecuta uno de los casos de prueba de forma aislada.

over 4 years ago · Santiago Trujillo Report

0

En mi situación, el error críptico se desencadenó al no importar HttpClientModule al archivo de prueba. Más detalles aquí .

over 4 years ago · Santiago Trujillo Report

0

Ejecute broma con --detectOpenHandles . Esto le mostrará lo que realmente está mal con su especificación de prueba. Para mí, faltaban importaciones de material angular y simulacros de servicio. Es posible que se le solicite que agregue BrowserAnimationsModule , como aludió Nambi en su respuesta

paquete.json:

 "test": "jest --detectOpenHandles"
over 4 years ago · Santiago Trujillo Report

0

Tuve este mismo problema al ejecutar jest con --watch . Eliminar --watch detuvo el error.

over 4 years ago · Santiago Trujillo Report

0

Este mensaje suele aparecer, si hay un error, que no se resuelve en una excepción estándar.

Como lo mencionó @JamesBarret, el uso de la función jests detect open handle le proporcionará un buen mensaje de error que le indicará cuál es el problema real detrás de este mensaje.

Sin embargo, el identificador --detectOpenHandles mencionado en el otro mensaje está en desuso y se reemplazó con --detect-open-handles .

Puedes usar: (en tu cli)

 jest --detect-open-handles

O en un archivo package.json:

 "test": "jest --detect-open-handles"

O como fue en mi caso una prueba angular:

 ng test --detect-open-handles
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!