首页 文章

Karma:Angular 4没有服务提供商

提问于
浏览
1

您想在我的角度组件中测试真实的服务 . 但我得到低于错误 . No provider for Service blservice

来自'@ angular / core / testing'的`import {async,getTestBed,TestBed,inject};

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();
 }));
 });`

错误:

错误:没有BlService的提供者!错误:没有BlService的提供者!在ReflectiveInjector_.prototype.throwOrNull(http://localhost:9876/karma_webpack/vendor.bundle.js:42115:13)在ReflectiveInjector.prototype.getByKeyDefault(http://localhost:9876/karma_webpack/vendor.bundle.js:42154:13)在ReflectiveInjector.prototype.getByKey(http://localhost:9876/karma_webpack/vendor.bundle.js:42086:13)在ReflectiveInjector.prototype.get(http://localhost:9876/karma_webpack/vendor.bundle.js:41955:9)在resolveNgModuleDep(http://localhost:9876/karma_webpack/vendor.bundle.js:48958:5)在NgModuleRef_.prototype.get(http://localhost:9876/karma_webpack/vendor.bundle.js:50028:9

1 回答

  • 3

    以这种方式解决它:

    import {async} from '@angular/core/testing';
    
    
    beforeEach(async(() => {
      TestBed.configureTestingModule({
        providers: [BlService]
      });
    }));
    

相关问题