Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Karma : Angular 4 No provider for Service

Hi would like to test the real service with in my angular component. but im getting below error. No provider for Service blservice

import {async, getTestBed,TestBed, inject } from '@angular/core/testing';

import { BlService } from './bl.service';
import { Injectable } from '@angular/core';
import { BaseRequestOptions, Http, Response, ResponseOptions, XHRBackend} from '@angular/http';

describe('BlService', () => {

  beforeEach(() => {TestBed.configureTestingModule({
    providers: [BlService]
   });
  });

  it('should be created', inject([BlService], (service: BlService) => {
    expect(service).toBeTruthy();
  }));
});

ERROR :

Error: No provider for BlService! Error: No provider for BlService!
at ReflectiveInjector_.prototype._throwOrNull (http://localhost:9876/_karma_webpack_/vendor.bundle.js:42115:13)
at ReflectiveInjector_.prototype._getByKeyDefault (http://localhost:9876/_karma_webpack_/vendor.bundle.js:42154:13)
at ReflectiveInjector_.prototype._getByKey (http://localhost:9876/_karma_webpack_/vendor.bundle.js:42086:13)
at ReflectiveInjector_.prototype.get (http://localhost:9876/_karma_webpack_/vendor.bundle.js:41955:9) at resolveNgModuleDep (http://localhost:9876/_karma_webpack_/vendor.bundle.js:48958:5) at NgModuleRef_.prototype.get (http://localhost:9876/_karma_webpack_/vendor.bundle.js:50028:9)

like image 942
user7436928 Avatar asked Jan 25 '18 17:01

user7436928


1 Answers

Solve it this way:

import {async} from '@angular/core/testing';


beforeEach(async(() => {
  TestBed.configureTestingModule({
    providers: [BlService]
  });
}));
like image 110
Wenceslao Hoz Nogueira Avatar answered Nov 14 '22 12:11

Wenceslao Hoz Nogueira