Created
October 8, 2019 12:01
-
-
Save IAfanasovMob/a1737320e1fea5aae4a683222e247a3c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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