How to fix [karma-server]: Uncaught Exception

Viewed 1258

I have running Angular 9 application and I am running unit test in jasmine using the below command to run the tests and everything works fine:

ng test

But, when I am running unit test using watch=false, all the tests are passing, but I am getting "UncaughtException" at the end.

ng test --watch=false // using this command in SonarQube to generate UT report

enter image description here

SonarQube is not genearting UT report because of the above error.

Is there any way to get the details of the error (log files or something) or debug the [karma-server]" UncaughtException error...?

I am getting error from the below spec file:

profile.component.spec.ts

describe('Client.App.Advanced.ProfileComponent', () => {
    let component: ProfileComponent;
    let fixture: ComponentFixture<ProfileComponent>;
    let httpMock: HttpTestingController;

    function mockHttp(data) {
        const mockReq = httpMock.expectOne((req) => true);
        mockReq.flush(data);
        httpMock.verify();
    }

    beforeEach(async(() => {
        TestBed.configureTestingModule({
            imports: [HttpClientTestingModule, RouterTestingModule],
            declarations: [ProfileComponent],
            providers: [ProfileToolHandlerService ]
        }).compileComponents();
    }));

    beforeEach(fakeAsync(() => {
        httpMock = TestBed.inject<HttpTestingController>(HttpTestingController);
        fixture = TestBed.createComponent(ProfileComponent);
        component = fixture.componentInstance;
        fixture.detectChanges();
        // mock request for Login
        mockHttp(null);
        tick();
    }));

    it('shall create the component', () => {
        fixture.detectChanges();
        expect(component).toBeDefined();
    });
}
0 Answers
Related