programing

처리되지 않은 약속거부 경고:유형 오류: Jest + Angular를 사용하여 원형 구조를 JSON으로 변환하는 중

lovejava 2023. 8. 2. 08:37

처리되지 않은 약속거부 경고:유형 오류: Jest + Angular를 사용하여 원형 구조를 JSON으로 변환하는 중

just-preset-angular를 사용하여 단위 테스트를 수행하지만 다음과 같은 경고를 받았습니다.UnhandledPromiseRejectionWarning: TypeError: Converting circular structure to JSON오류의 원인이 무엇인지 확실하지 않습니다. 이로 인해 응용 프로그램이 고착되고 다른 장치 테스트를 실행하지 않습니다.

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

노드를 실행하는 방법을 잘 모르겠습니다. 추적 경고입니다.직렬화 문제인 것 같습니다. 경고에 불과하지만 문제가 어디에 있는지는 잘 모르겠습니다.예외를 찾을 수 있는 더 좋은 방법이 있습니까?

농담하기--detectOpenHandles검사 사양에 실제로 어떤 문제가 있는지 알 수 있습니다.저는 Angular Material 수입품과 서비스 모크가 누락되었습니다.다음을 추가하라는 메시지가 표시될 수 있습니다.BrowserAnimationsModule남비가 그의 대답에서 암시한 바와 같이.

꾸러미json:

"test": "jest --detectOpenHandles"

일반적으로 이 메시지는 오류가 있는 경우 표준 예외로 해결되지 않고 표시됩니다.

@James Barret이 농담을 사용하여 언급한 것처럼.detect open handle기능은 이 메시지 뒤에 숨겨진 진짜 문제가 무엇인지 알려주는 좋은 오류 메시지를 제공합니다.

손잡이 --detectOpenHandles그러나 다른 메시지에서 언급된 내용은 더 이상 사용되지 않으며 다음으로 대체되었습니다.--detect-open-handles.

다음을 사용할 수 있습니다. (cli에서)

jest --detect-open-handles

아니면 포장지에.json 파일:

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

또는 제 경우에는 각도 테스트와 마찬가지로컬 테스트:

ng test --detect-open-handles

놓친 사람을 돕기 위해 내 대답을 추가하는 것.제 경우에는 가져오기를 놓쳤습니다.

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

테스트 케이스 중 하나를 별도로 실행하는 경우에만 문제를 찾을 수 있습니다.

비동기 작업에 문제가 있었으므로 아래와 같이 테스트 케이스를 작성하여 문제를 해결해 주십시오.

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()
  });
});

내 상황에서 암호화 오류는 가져오기를 수행하지 않아 발생했습니다.HttpClientModule테스트 파일에 저장합니다.자세한 내용은 여기에 있습니다.

저는 농담을 할 때 같은 문제를 겪었습니다.--watch제거 중--watch오류를 중지했습니다.

일부 비동기 작업이 수행되어 오류가 발생한 것 같습니다.waitForAsync 함수 안에 장치 테스트를 포장해 보십시오.

언급URL : https://stackoverflow.com/questions/63895685/unhandledpromiserejectionwarning-typeerror-converting-circular-structure-to-js