テスト モジュールで提供されているモック サービスからの応答を受信できません。
私は何かを省略していますか?
エラーが表示されます: TypeError: undefined is not a constructor (evaluating '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');
});
});
});