I've been utilizing the angular-cli testing framework for my project.
Within one of my components, I decided to include the 'ng2-slim-loading-bar' node module.
submit(){
this._slimLoadingBarService.start(() => {
});
//performing method operations
}
During the testing phase of this component, I implemented spyOn on this service in the following manner:
beforeEach(() => {
let slimLoadingBarService=new SlimLoadingBarService();
demoComponent = new DemoComponent(slimLoadingBarService);
TestBed.configureTestingModule({
declarations: [
DemoComponent
],
providers: [
{ provide: SlimLoadingBarService, useClass: SlimLoadingBarService}
],
imports: [
SharedModule
]
});
});
it('should successfully pass data to the service', () => {
spyOn(slimLoadingBarService,'start').and.callThrough();
//testing code;if I exclude the above service from my component, the test runs smoothly
});
However, it doesn't seem to be working as expected.
An error is being thrown which states:
spyOn could not find an object to spy upon for start()