TestBed for HttpInterceptor shows NullInjectorError: No provider for Events


#1

I’ve created HttpInterceptor, and I’m using Events in constructor as shown. I’ve wrote TestBed for it, but when I start Karma, it shows an error:
Error: StaticInjectorError[Events]:
StaticInjectorError[Events]:
NullInjectorError: No provider for Events!
How can I provide Events in TestBed?

// My HttpInterceptor
import {HttpEvent, HttpHandler, HttpInterceptor, HttpRequest} from “@angular/common/http”;
import {Injectable} from “@angular/core”;
import {Events} from “ionic-angular”;
import {Observable} from “rxjs/Observable”;

@Injectable()
export class APIAuthInterceptorProvider implements HttpInterceptor {
private userProfileDetails;
private clubProfileDetails;

constructor(private connectionEvent: Events) {
}

. . .


#2

You will need to put in as your providers…

 beforeEach(async() => {
        TestBed.configureTestingModule({
            imports: [HttpClientTestingModule],
            providers: [
                AuthProvider, 
                { provide: Events, useClass: Events },
            ], 
        });
    })