我想问一下测试从内联服务接收数据的属性的常见做法是什么。
我无法测试从服务定义的内联值接收值的属性。这是我的财产
readonly filters$ = forkJoin({
institutions: this.dataExtractService.getInstitutions(),
dataSetTypes: this.dataExtractService.getDataSetTypes()
});
getInstitutions()
并getDataSetTypes()
返回Observable<string()>
这是我的规格
let component: ExtractRetrievalComponent;
let fixture: ComponentFixture<ExtractRetrievalComponent>;
let formBuilder: FormBuilder;
let dataExtractService: DataExtractService;
beforeEach(() => {
TestBed.configureTestingModule({
schemas: [NO_ERRORS_SCHEMA],
imports: [HttpClientTestingModule],
declarations: [ExtractRetrievalComponent],
providers: [
FormBuilder, DataExtractService
]
}).compileComponents();
fixture = TestBed.createComponent(ExtractRetrievalComponent);
component = fixture.componentInstance;
formBuilder = TestBed.inject(FormBuilder);
dataExtractService = TestBed.inject(DataExtractService);
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should get filters', (done) => {
const expectedInstitution = ['expectedInstitutions'] as string[];
const expectedDataSetType = ['expectedDataSetType'] as string[];
const expectedFilter = {
institutions: expectedInstitution,
dataSetTypes: expectedDataSetType
};
spyOn(component.filters$, 'subscribe').and.callThrough();
spyOn(dataExtractService, 'getInstitutions').and.returnValue(of(expectedInstitution));
spyOn(dataExtractService, 'getDataSetTypes').and.returnValue(of(expectedDataSetType));
fixture.detectChanges();
component.filters$.subscribe(result => {
expect(result).toEqual(expectedFilter);
done();
});
});
测试失败,结果
Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL)
我也增加了超时间隔,但没有运气。有什么提示吗?