1
+ import { filter } from 'rxjs/operators' ;
1
2
import { async , ComponentFixture , fakeAsync , flush , flushMicrotasks , TestBed , waitForAsync } from '@angular/core/testing' ;
2
3
import { CoursesModule } from '../courses.module' ;
3
4
import { DebugElement } from '@angular/core' ;
@@ -21,6 +22,10 @@ describe('HomeComponent', () => {
21
22
let fixture : ComponentFixture < HomeComponent > ;
22
23
let component : HomeComponent ;
23
24
let el : DebugElement ;
25
+ let coursesService : any ;
26
+
27
+ const beginnerCourses = setupCourses ( )
28
+ . filter ( course => course . category == 'BEGINNER' ) ;
24
29
25
30
beforeEach ( waitForAsync ( ( ) => {
26
31
const coursesServiceSpy = jasmine . createSpyObj ( 'CoursesService' , [ 'findAllCourses' ] ) ;
@@ -42,6 +47,7 @@ describe('HomeComponent', () => {
42
47
fixture = TestBed . createComponent ( HomeComponent ) ;
43
48
component = fixture . componentInstance ;
44
49
el = fixture . debugElement ;
50
+ coursesService = TestBed . inject ( CoursesService ) ;
45
51
} ) ;
46
52
47
53
} ) ) ;
@@ -54,9 +60,11 @@ describe('HomeComponent', () => {
54
60
55
61
56
62
it ( "should display only beginner courses" , ( ) => {
57
-
58
- pending ( ) ;
59
-
63
+ coursesService . findAllCourses . and
64
+ . returnValue ( of ( beginnerCourses ) ) ;
65
+ fixture . detectChanges ( ) ;
66
+ const tabs = el . queryAll ( By . css ( ".mat-tab-label" ) ) ;
67
+ expect ( tabs . length ) . toBe ( 1 , "unexpected number of tabs found" ) ;
60
68
} ) ;
61
69
62
70
0 commit comments