如何在Angular2单元测试中导入或注入AngularJS服务
我在AngularJS有自己的一项服务。我在Angular 2中的一个组件中使用了它。现在,当我为组件编写单元测试时,我无法导入或注入该服务。有谁能帮我解决这个问题。您需要使用Angular TestBed设置测试并注入服务如何在Angular2单元测试中导入或注入AngularJS服务,angularjs,Angularjs,我在AngularJS有自己的一项服务。我在Angular 2中的一个组件中使用了它。现在,当我为组件编写单元测试时,我无法导入或注入该服务。有谁能帮我解决这个问题。您需要使用Angular TestBed设置测试并注入服务 import { TestBed, async, ComponentFixture } from '@angular/core/testing'; describe('', () => { let fixture: ComponentFixture<Tes
import { TestBed, async, ComponentFixture } from '@angular/core/testing';
describe('', () => {
let fixture: ComponentFixture<TestComponent>;
let component: TestComponent;
let service;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
AppModule
],
declarations: [
],
providers: [
]}).compileComponents()
.then(() => {
fixture = TestBed.createComponent(TestComponent);
comp = fixture.componentInstance;
service = TestBed.get(AppService);
});
}));
});
it('should fetch the cluster list on init', async(() => {
expect(service.getList).toHaveBeenCalled();
});