加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Angular 4测试 – 抛出[object ErrorEvent]

发布时间:2020-12-17 10:24:58 所属栏目:安全 来源:网络整理
导读:我正在为我的角度应用完成测试台.但是在业力 – 茉莉花测试中存在一个问题,它会引发错误 [object ErrorEvent] thrown 我将node_modules更新为我在以下链接中找到的解决方案 How do I debug a “[object ErrorEvent] thrown” error in my Karma/Jasmine test
我正在为我的角度应用完成测试台.但是在业力 – 茉莉花测试中存在一个问题,它会引发错误

[object ErrorEvent] thrown

我将node_modules更新为我在以下链接中找到的解决方案
How do I debug a “[object ErrorEvent] thrown” error in my Karma/Jasmine tests?

但现在错误随机出现,有时候测试床没有任何故障,有时会出现错误触发.有任何建议可以永久避免它吗?

PS – 如果您需要更多资源,请在评论中告诉我.谢谢!

SomeComponent.spec.ts

import { RouterTestingModule } from '@angular/router/testing';
import { FormsModule,ReactiveFormsModule } from '@angular/forms';
import { NgModule } from '@angular/core';
import { HttpClient,HttpClientModule } from '@angular/common/http';
import { TranslateLoader,TranslateModule } from '@ngx-translate/core';
import { async,ComponentFixture,TestBed } from '@angular/core/testing';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';

import { SomeComponent } from './some.component';
import { HttpLoaderFactory } from '../app.module';
import { AppRoutingModule } from '../app-routing.module';    
import { SomeService } from './../services/some.service';

describe('SomeComponent',() => {
  let component: SomeComponent;
  let fixture: ComponentFixture<SomeComponent>;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      imports: [
        TranslateModule.forRoot({
          loader: {
            provide: TranslateLoader,useFactory: HttpLoaderFactory,deps: [HttpClient]
          }
        }),HttpClientModule,AppRoutingModule,FormsModule,ReactiveFormsModule,RouterTestingModule,NgbModule.forRoot(),],declarations: [
        SomeComponent
       ],providers: [
        SomeService
       ]
    })
    .compileComponents();
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(SomeComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

  it('should create',() => {
    expect(component).toBeTruthy();
  });
});
我遇到了同样的问题,结果证明升级到jasmine-core 3.0.0导致了这个问题,所以我降级到了2.5.2并且工作正常.
我认为这是因为karma-jasmine还不兼容jasmine 3.0.0

这就是我现在拥有的:

"jasmine": "2.5.2","jasmine-core": "2.5.2","karma-jasmine": "1.1.2",

有关该问题的详细信息,请参阅:

https://github.com/jasmine/jasmine/issues/1523

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读