次の角度(4)コンポーネントテストがあります。コンポーネントには、this.jobService.subscribeEvent('thisline')
という行があります。 { provide: JobService, useClass: MockJobService }
:私はこの行を含めるようにテストを変更した場合、しかし、角度テストはモックサービスクラスでのみ動作しますが、値ではありません
TypeError: Cannot read property 'subscribe' of undefined
:私はこのテストを実行すると
class MockJobService {
public subscribeEvent(line: string): Observable<any> {
return Observable.of({ action: 'dwnTime' } })
}
}
describe('NotificationComponent',() => {
let component: NotificationComponent;
let fixture: ComponentFixture<NotificationComponent>;
let mockJobService = new MockJobService();
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [NotificationComponent],
providers: [
{ provide: JobService, useValue: mockJobService }
]
}).compileComponents();
}));
私はエラーを取得します。その後、テストは機能しますが、私はsubscribeEvent
関数でスパイを実行したいので、動作させるにはuseValue
バージョンが必要です。何が間違っているのでしょうか?