I'm in the process of completing the test bed for my angular application. But there is an issue in the karma-jasmine testing, which throws an error
[object ErrorEvent] thrown
I updated the node_modules as a solution I found in the following link How do I debug a "[object ErrorEvent] thrown" error in my Karma/Jasmine tests?
But now error throws at random times, sometimes test bed is completed without any fault, sometimes above error triggers. Any suggestions to avoid it permanently?
PS - Let me know in the comments if you need more resources. Thanks!
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(),
FormsModule,
ReactiveFormsModule,
],
declarations: [
SomeComponent
],
providers: [
SomeService
]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(SomeComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
I had the same issue and it turned out that the upgrade to jasmine-core 3.0.0 cause the issue, so I downgraded to 2.5.2 and things worked fine.
I think that's because karma-jasmine
is not yet compatible with jasmine 3.0.0
That's what I have now:
"jasmine": "2.5.2",
"jasmine-core": "2.5.2",
"karma-jasmine": "1.1.2",
For more details about the issue see:
https://github.com/jasmine/jasmine/issues/1523
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With