0
私はhttp呼び出しを行うサービスを呼び出ししようとしています。私は疑似偽のデータを供給し、テストでそれをチェックしたいと思います。spyOnとreturnValueにデータを渡します。
ここは私の設定です。
beforeEach(() => {
fixture = TestBed.createComponent(MhSearchFormComponent);
component = fixture.componentInstance;
component.propertyCount = 0;
spyOn(component._searchService, 'getCount').and.returnValue({ subscribe:() => {} });
fixture.detectChanges();
});
私はスパイの見返りにpropertyCount
値を再割り当てします。
は、ここに私のテストです:私はこれを試してみた
it('should get a count on load',() => {
expect(component.propertyCount).toBe('1000');
});
が、それは私があなたのコンポーネント/サービスがどのように見えるか分からない
spyOn(component._searchService, 'getCount').and.returnValue({ subscribe:() => {'Count':1000} });
これはトリックでした。ありがとうございました! – abyrne85