Skip to content

Commit 07b1731

Browse files
committed
Angular Testing Course
1 parent 584e6f9 commit 07b1731

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
2+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
3+
4+
import { CourseComponent } from './course.component';
5+
import {CoursesModule} from '../courses.module';
6+
import {CoursesService} from '../services/courses.service';
7+
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
8+
import {ActivatedRoute} from '@angular/router';
9+
import {COURSES} from '../../../../server/db-data';
10+
import {of} from 'rxjs';
11+
import {setupCourses} from '../common/setup-test-data';
12+
13+
describe('CourseComponent', () => {
14+
let component: CourseComponent;
15+
let fixture: ComponentFixture<CourseComponent>;
16+
17+
beforeEach(async(() => {
18+
19+
const courseServicesSpy = jasmine.createSpyObj('CoursesService', ['findLessons']);
20+
21+
courseServicesSpy.findLessons.and.returnValue(of());
22+
23+
const mockActivatedRoute = {
24+
snapshot: {
25+
data: {
26+
course: COURSES[12]
27+
}
28+
}
29+
};
30+
31+
TestBed.configureTestingModule({
32+
imports: [
33+
CoursesModule,
34+
NoopAnimationsModule
35+
],
36+
providers: [
37+
{provide: ActivatedRoute, useValue: mockActivatedRoute},
38+
{provide: CoursesService, useValue: courseServicesSpy},
39+
40+
]
41+
}).compileComponents();
42+
43+
44+
}));
45+
46+
beforeEach(() => {
47+
fixture = TestBed.createComponent(CourseComponent);
48+
component = fixture.componentInstance;
49+
fixture.detectChanges();
50+
});
51+
52+
it('should create the component', () => {
53+
expect(component).toBeTruthy();
54+
});
55+
56+
it('should display the course data', () => {
57+
pending();
58+
});
59+
60+
it('should display the course lessons', () => {
61+
pending();
62+
});
63+
64+
it('should load the next page of lessons', () => {
65+
pending();
66+
});
67+
68+
it('should search for lessons', () => {
69+
pending();
70+
});
71+
72+
73+
});

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

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ describe('HomeComponent', () => {
3434
{provide: CoursesService, useValue: courseServicesSpy}
3535
]
3636
}).compileComponents();
37+
38+
3739
}));
3840

3941

0 commit comments

Comments
 (0)