我没有收到来自测试模块中提供的模拟服务的响应。
我遗漏了什么吗?
我收到错误: TypeError: undefined is not a constructor (evalating 'service.getUser.subscribe')*
class MockUserService {
getUser: jasmine.createSpy('getUser').and.returnValue(Observable.of({'name': 'user1'})),
getUser2: jasmine.createSpy('getUser2').and.returnValue(new BehaviorSubject({'name': 'user2'}))
}
fdescribe('should use mocked services', () => {
let component: TestComponent;
let fixture: ComponentFixture<TestComponent>;
let service;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [.....],
providers: [{provide: UserService, useClass: MockUserService}],
declarations: [TestComponent],
schemas: [NO_ERRORS_SCHEMA]
})
.compileComponents();
service = TestBed.get(UserService);
}));
beforeEach(() => {
fixture = TestBed.createComponent(TestComponent);
component = fixture.componentInstance;
});
it(`should provide mocked service`, () => {
service.getUser.subscribe(user => {
console.log(`user: ${user}`);
expect(user.name).toBe('user1');
});
service.getUser2.subscribe(user => {
console.log(`user: ${user}`);
expect(user.name).toBe('user2');
});
});
});