Angular-UnhandledPromisejectionWarning zone.js中的Jest问题
目前正在尝试以角度执行Jest。从Angular-UnhandledPromisejectionWarning zone.js中的Jest问题,angular,jestjs,zone,Angular,Jestjs,Zone,目前正在尝试以角度执行Jest。从ZoneLegate获取未处理的承诺错误。似乎无法解决。试图将zone.js更新为11版本,但这似乎产生了新问题 我尝试将async添加到spec.ts中,但这似乎无法解决问题 低于我当前的spec.ts import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { ForOthersDashboardComponent } from './for-othe
ZoneLegate
获取未处理的承诺错误。似乎无法解决。试图将zone.js
更新为11
版本,但这似乎产生了新问题
我尝试将async
添加到spec.ts中,但这似乎无法解决问题
低于我当前的spec.ts
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ForOthersDashboardComponent } from './for-others-dashboard.component';
describe('ForOthersDashboardComponent', () => {
let component: ForOthersDashboardComponent;
let fixture: ComponentFixture<ForOthersDashboardComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ForOthersDashboardComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ForOthersDashboardComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
编辑
该错误似乎只发生在导入所需模块的规范文件中。例如下面的spec文件。它正试图从节点\u模块中加载找不到的内容。我通过设置模块路径尝试了其他解决方案,但这似乎无法解决此问题
import { RequiredModule } from 'required-module-lib';
describe('DashboardComponent', () => {
let component: DashboardComponent;
let fixture: ComponentFixture<DashboardComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
RequiredModule
],
declarations: [
DashboardComponent
]
})
.compileComponents()
.then(() => {
fixture = TestBed.createComponent(DashboardComponent);
component = fixture.componentInstance;
fixture.detectChanges();
})
.catch(err => console.error(err));
}));
从'required module lib'导入{required module};
描述('DashboardComponent',()=>{
let组件:仪表板组件;
let夹具:组件夹具;
beforeach(异步(()=>{
TestBed.configureTestingModule({
进口:[
必需模块
],
声明:[
仪表板组件
]
})
.compileComponents()
.然后(()=>{
fixture=TestBed.createComponent(仪表板组件);
组件=fixture.componentInstance;
fixture.detectChanges();
})
.catch(err=>console.error(err));
}));
将所有导入的组件和服务检查到测试中。一些JSON.stringify
会导致此错误。可能是由于错误的模拟过程或与提供错误值相关的任何原因。请考虑发布错误消息而不是图像,这至少会使问题可搜索。这只会在特定模块中发生,对吗不是吗?应该指定模块,因为它非常相关。请参阅。我通过设置模块路径尝试了其他解决方案,但这似乎无法解决此问题-具体是什么?
import { RequiredModule } from 'required-module-lib';
describe('DashboardComponent', () => {
let component: DashboardComponent;
let fixture: ComponentFixture<DashboardComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
RequiredModule
],
declarations: [
DashboardComponent
]
})
.compileComponents()
.then(() => {
fixture = TestBed.createComponent(DashboardComponent);
component = fixture.componentInstance;
fixture.detectChanges();
})
.catch(err => console.error(err));
}));