10
votes

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)

1
can any one help on this pleaseuser7436928

1 Answers

19
votes

Solve it this way:

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


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