Модульные тесты не дают результатов в приложении Angular ngrx - PullRequest
0 голосов
/ 02 мая 2019

В моем приложении Angular-ngrx я пишу два модульных теста, чтобы проверить результат ответа службы.Неважно, что я меняю, тесты, кажется, проходят всегда.Я что-то упустил?

// effect.ts

@Injectable()
export class ContactInfoEffect {
  @Effect()
  fetchContactInfoResponse = this.actions.pipe(
    ofType(CONTACT_INFO_RESPONSE_REQUESTED),
    delay(250),
        mergeMap(contactInfo =>
            this.contactTriageService.getContentInfo().
            pipe(map(contacts => new ContactInfoSucceeded(contacts)),
             ),
             catchError(() => of(new ContactInfoFailed()))
        )
  )

  constructor(
    private actions: Actions,
    private contactTriageService: ContactTriageService
  ) { }
}

// spec.ts

 it('should dispatch `ContactInfoSucceeded` if the service returns successfully', () => {
    const response:ContactInfoResponse =  getContactInfoMock();
    const contactTriageServiceSpy = spyOn(
        contactTriageService,
      'getContentInfo'
    ).and.returnValue(of( [
        getContactInfoMock()
      ]));
    actions = new ReplaySubject(1);
    actions.next(new ContactInfoSucceeded(getContactInfoMock()));
    effects.fetchContactInfoResponse.subscribe((result) => {
      expect(contactTriageServiceSpy).toHaveBeenCalled();
      expect(result).toEqual(new ContactInfoSucceeded(response));
    });
  });

  it('should dispatch `ContactInfoFailed` if the service fails', () => {
    // const response:ContactInfoResponse =  getContactInfoMock();
    // const response =  null;
    const contactTriageServiceSpy = spyOn(
        contactTriageService,
      'getContentInfo'
    ).and.returnValue(throwError(null));
    actions = new ReplaySubject(1);
    actions.next(new ContactInfoFailed());
    effects.fetchContactInfoResponse.subscribe((result) => {
      expect(contactTriageServiceSpy).toHaveBeenCalled();
      expect(result).toEqual(new ContactInfoSucceeded(getContactInfoMock()));
    });
  });
...