Skip to content

Commit 483ace3

Browse files
committed
test: added home component test
1 parent cd92707 commit 483ace3

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { filter } from 'rxjs/operators';
12
import { async, ComponentFixture, fakeAsync, flush, flushMicrotasks, TestBed, waitForAsync } from '@angular/core/testing';
23
import { CoursesModule } from '../courses.module';
34
import { DebugElement } from '@angular/core';
@@ -21,6 +22,10 @@ describe('HomeComponent', () => {
2122
let fixture: ComponentFixture<HomeComponent>;
2223
let component: HomeComponent;
2324
let el: DebugElement;
25+
let coursesService: any;
26+
27+
const beginnerCourses = setupCourses()
28+
.filter(course => course.category == 'BEGINNER');
2429

2530
beforeEach(waitForAsync(() => {
2631
const coursesServiceSpy = jasmine.createSpyObj('CoursesService', ['findAllCourses']);
@@ -42,6 +47,7 @@ describe('HomeComponent', () => {
4247
fixture = TestBed.createComponent(HomeComponent);
4348
component = fixture.componentInstance;
4449
el = fixture.debugElement;
50+
coursesService = TestBed.inject(CoursesService);
4551
});
4652

4753
}));
@@ -54,9 +60,11 @@ describe('HomeComponent', () => {
5460

5561

5662
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");
6068
});
6169

6270

0 commit comments

Comments
 (0)