Skip to content

Commit 0359240

Browse files
author
Dave Syer
committed
Test HTTP client usage as well
1 parent cc72157 commit 0359240

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/main/client/src/app/app.component.spec.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { TestBed, async } from '@angular/core/testing';
22
import { AppComponent } from './app.component';
3-
import { HttpClientTestingModule } from '@angular/common/http/testing'
3+
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'
44
describe('AppComponent', () => {
55
beforeEach(async(() => {
66
TestBed.configureTestingModule({
@@ -26,4 +26,11 @@ describe('AppComponent', () => {
2626
const compiled = fixture.debugElement.nativeElement;
2727
expect(compiled.querySelector('h1').textContent).toContain('Welcome Demo!');
2828
}));
29+
it('should fetch data from backend', async(() => {
30+
const http = TestBed.get(HttpTestingController);
31+
const fixture = TestBed.createComponent(AppComponent);
32+
const app = fixture.debugElement.componentInstance;
33+
http.expectOne('resource').flush({id:'XYZ',content:'Hello'});
34+
expect(app.data.content).toContain('Hello');
35+
}));
2936
});

0 commit comments

Comments
 (0)