File tree Expand file tree Collapse file tree 1 file changed +8
-1
lines changed
Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change 11import { TestBed , async } from '@angular/core/testing' ;
22import { AppComponent } from './app.component' ;
3- import { HttpClientTestingModule } from '@angular/common/http/testing'
3+ import { HttpClientTestingModule , HttpTestingController } from '@angular/common/http/testing'
44describe ( '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} ) ;
You can’t perform that action at this time.
0 commit comments