Skip to content

Instantly share code, notes, and snippets.

@IAfanasovMob
Created October 8, 2019 12:01
Show Gist options
  • Save IAfanasovMob/a1737320e1fea5aae4a683222e247a3c to your computer and use it in GitHub Desktop.
Save IAfanasovMob/a1737320e1fea5aae4a683222e247a3c to your computer and use it in GitHub Desktop.
it('should show error message when request fails', async () => {
component.userName = 'IAfanasov';
fixture.debugElement.query(By.css('button')).nativeElement.click();
const request = httpMock.expectOne('https://api.github.com/users/IAfanasov/starred');
request.error(null);
fixture.detectChanges();
await fixture.whenRenderingDone();
const alert = fixture.debugElement.query(By.css('.alert-danger'));
expect(alert).toBeTruthy();
});
it('should hide the error message when request succeeded after failed one fails', async () => {
component.userName = 'IAfanasov';
fixture.debugElement.query(By.css('button')).nativeElement.click();
const requestToFail = httpMock.expectOne('https://api.github.com/users/IAfanasov/starred');
requestToFail.error(null);
fixture.debugElement.query(By.css('button')).nativeElement.click();
const requestToSucceed = httpMock.expectOne('https://api.github.com/users/IAfanasov/starred');
requestToSucceed.flush([]);
fixture.detectChanges();
await fixture.whenRenderingDone();
const alert = fixture.debugElement.query(By.css('.alert-danger'));
expect(alert).toBeFalsy();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment