茉莉花测试与可观察和数组

时间:2018-11-27 10:04:52

标签: javascript angular karma-jasmine

我有一个有角度的应用程序,我正忙于用Jasmine进行测试。

我有这种方法:

tintColor

以及到目前为止的单元测试:

unselectedItemTintColor

但是不会。

在这一行上我得到一个错误:

/** Gets the case type info configuration that is used on various views */
    getCaseTypeInfo(spinnerMessage: string): Observable<CaseTypeInfoModel[]> {
        let result: Observable<CaseTypeInfoModel[]>;
        Iif (this.caseTypeInfoSnapshot) {
            result = of(this.caseTypeInfoSnapshot);
        } else {
            result = this.http.get<CaseTypeInfoModel[]>(`${this.api}/types`, spinnerMessage).pipe(map(i => {
                this.caseTypeInfoStoreService.addCaseTypeInfoToStore(i);
                return i;
            }));
        }
        return result;
    }

谢谢

我现在这样子:

 // tslint:disable-next-line:no-commented-code
    it('shoud get case type info configuration that is used on various views', () => {
        let result99: Observable<CaseTypeInfoModel[]>;
        result99 =  service.getCaseTypeInfo('spinner') as Observable<CaseTypeInfoModel[]>;
        const castTypeinfoModelTest = new Array<CaseTypeInfoModel>();

        service.getCaseTypeInfo('spinner');
        caseTypeInfoStoreService.addCaseTypeInfoToStore();
        afwHttpMock.setupOnlyResponse(result99, 200);
        expect(castTypeinfoModelTest).toBe(true);

    });

但这部分仍然是红色的:

 expect(castTypeinfoModelTest).toBe(true);

此方法:

 it('shoud get case type info configuration that is used on various views when snapshot doesnt exists', () => {
        let result99: Observable<CaseTypeInfoModel[]>;
         const spy = spyOn(caseTypeInfoStoreService, 'addCaseTypeInfoToStore');
        result99 = service.getCaseTypeInfo('spinner') as Observable<CaseTypeInfoModel[]>;
        const response = [{ mock: 'mock' } as any];
        service['caseTypeInfoSnapshot'] = response;
        caseTypeInfoStoreService.addCaseTypeInfoToStore();

         afwHttpMock.setupOnlyResponse(result99, 200);
         expect(spy).toHaveBeenCalledWith('spinner');
          afwHttpMock.returnSuccessResponse();
    });

0 个答案:

没有答案