@@ -15,16 +15,15 @@ import {NoopAnimationsModule} from '@angular/platform-browser/animations';
15
15
16
16
17
17
18
- fdescribe ( 'HomeComponent' , ( ) => {
18
+ describe ( 'HomeComponent' , ( ) => {
19
19
20
20
let fixture : ComponentFixture < HomeComponent > ;
21
21
let component :HomeComponent ;
22
22
let el : DebugElement ;
23
- let courseServicesSpy : any ;
24
23
25
- courseServicesSpy = jasmine . createSpyObj ( 'CoursesService' , [ 'findAllCourses' ] ) ;
24
+ beforeEach ( ( ( ) => {
26
25
27
- beforeEach ( async ( ( ) => {
26
+ const courseServicesSpy = jasmine . createSpyObj ( 'CoursesService' , [ 'findAllCourses' ] ) ;
28
27
29
28
TestBed . configureTestingModule ( {
30
29
imports : [
@@ -35,36 +34,62 @@ fdescribe('HomeComponent', () => {
35
34
{ provide : CoursesService , useValue : courseServicesSpy }
36
35
]
37
36
} ) . compileComponents ( ) ;
37
+ } ) ) ;
38
+
38
39
40
+ beforeEach ( ( ) => {
39
41
fixture = TestBed . createComponent ( HomeComponent ) ;
40
- component = fixture . debugElement . componentInstance ;
42
+ component = fixture . componentInstance ;
41
43
el = fixture . debugElement ;
44
+ } ) ;
42
45
43
46
44
- } ) ) ;
45
-
46
-
47
- it ( "should create the component" , async ( ( ) => {
47
+ it ( "should create the component" , ( ) => {
48
48
49
49
expect ( component ) . toBeTruthy ( ) ;
50
50
51
- } ) ) ;
51
+ } ) ;
52
52
53
53
54
- it ( "should display only beginner courses" , async ( ( ) => {
54
+ it ( "should display only beginner courses" , ( ) => {
55
55
56
- courseServicesSpy . findAllCourses . and . returnValue ( of ( setupCourses ( ) . filter ( course => course . category == 'BEGINNER' ) ) ) ;
56
+ TestBed . get ( CoursesService ) . findAllCourses . and . returnValue (
57
+ of ( setupCourses ( ) . filter ( course => course . category == 'BEGINNER' ) ) ) ;
57
58
58
59
fixture . detectChanges ( ) ;
59
60
60
61
const tabs = el . queryAll ( By . css ( '.mat-tab-label' ) ) ;
61
62
62
63
expect ( tabs . length ) . toBe ( 1 , "Unexpected number of tabs found" ) ;
63
64
64
- } ) ) ;
65
+ } ) ;
66
+
67
+
68
+ it ( "should display only advanced courses" , ( ) => {
69
+
70
+ TestBed . get ( CoursesService ) . findAllCourses . and . returnValue (
71
+ of ( setupCourses ( ) . filter ( course => course . category == 'ADVANCED' ) ) ) ;
72
+
73
+ fixture . detectChanges ( ) ;
74
+
75
+ const tabs = el . queryAll ( By . css ( '.mat-tab-label' ) ) ;
76
+
77
+ expect ( tabs . length ) . toBe ( 1 , "Unexpected number of tabs found " ) ;
78
+
79
+ } ) ;
80
+
65
81
82
+ it ( "should display both tabs" , ( ) => {
83
+
84
+ TestBed . get ( CoursesService ) . findAllCourses . and . returnValue ( of ( setupCourses ( ) ) ) ;
85
+
86
+ fixture . detectChanges ( ) ;
87
+
88
+ const tabs = el . queryAll ( By . css ( '.mat-tab-label' ) ) ;
66
89
90
+ expect ( tabs . length ) . toBe ( 2 , "Expected to find 2 tabs" ) ;
67
91
92
+ } ) ;
68
93
69
94
} ) ;
70
95
0 commit comments