Skip to content

Commit c8ac5bf

Browse files
author
Your Name
committed
Angular Testing Course
1 parent fae3309 commit c8ac5bf

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

src/app/courses/home/home.component.spec.ts

+31-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ describe('HomeComponent', () => {
2121
let fixture: ComponentFixture<HomeComponent>;
2222
let component:HomeComponent;
2323
let el: DebugElement;
24+
let coursesService: any;
25+
26+
const beginnerCourses = setupCourses()
27+
.filter(course => course.category == 'BEGINNER');
28+
29+
const advancedCourses = setupCourses()
30+
.filter(course => course.category == 'ADVANCED');
2431

2532
beforeEach(async(() => {
2633

@@ -39,11 +46,14 @@ describe('HomeComponent', () => {
3946
fixture = TestBed.createComponent(HomeComponent);
4047
component = fixture.componentInstance;
4148
el = fixture.debugElement;
49+
coursesService = TestBed.get(CoursesService);
4250
});
4351

4452

4553
}));
4654

55+
56+
4757
it("should create the component", () => {
4858

4959
expect(component).toBeTruthy();
@@ -53,21 +63,39 @@ describe('HomeComponent', () => {
5363

5464
it("should display only beginner courses", () => {
5565

56-
pending();
66+
coursesService.findAllCourses.and.returnValue(of(beginnerCourses));
67+
68+
fixture.detectChanges();
69+
70+
const tabs = el.queryAll(By.css(".mat-tab-label"));
71+
72+
expect(tabs.length).toBe(1, "Unexpected number of tabs found");
5773

5874
});
5975

6076

6177
it("should display only advanced courses", () => {
6278

63-
pending();
79+
coursesService.findAllCourses.and.returnValue(of(advancedCourses));
80+
81+
fixture.detectChanges();
82+
83+
const tabs = el.queryAll(By.css(".mat-tab-label"));
84+
85+
expect(tabs.length).toBe(1, "Unexpected number of tabs found");
6486

6587
});
6688

6789

6890
it("should display both tabs", () => {
6991

70-
pending();
92+
coursesService.findAllCourses.and.returnValue(of(setupCourses()));
93+
94+
fixture.detectChanges();
95+
96+
const tabs = el.queryAll(By.css(".mat-tab-label"));
97+
98+
expect(tabs.length).toBe(2, "Expected to find 2 tabs");
7199

72100
});
73101

0 commit comments

Comments
 (0)