Skip to content

Commit 5226451

Browse files
author
Your Name
committed
Angular Testing Course
1 parent 7a9a968 commit 5226451

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

src/app/courses/services/courses.services.spec.ts

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {CoursesService} from './courses.service';
22
import {TestBed} from '@angular/core/testing';
33
import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing';
4-
import {COURSES} from '../../../../server/db-data';
4+
import {COURSES, findLessonsForCourse} from '../../../../server/db-data';
55
import {Course} from '../model/course';
66
import {HttpErrorResponse} from '@angular/common/http';
77

@@ -118,6 +118,33 @@ describe('CoursesService', () => {
118118
statusText:'Internal Server Error'});
119119
});
120120

121+
it('should find a list of lessons', () => {
122+
123+
coursesService.findLessons(12)
124+
.subscribe(lessons => {
125+
126+
expect(lessons).toBeTruthy();
127+
128+
expect(lessons.length).toBe(3);
129+
130+
});
131+
132+
const req = httpTestingController.expectOne(
133+
req => req.url == '/api/lessons');
134+
135+
expect(req.request.method).toEqual("GET");
136+
expect(req.request.params.get("courseId")).toEqual("12");
137+
expect(req.request.params.get("filter")).toEqual("");
138+
expect(req.request.params.get("sortOrder")).toEqual("asc");
139+
expect(req.request.params.get("pageNumber")).toEqual("0");
140+
expect(req.request.params.get("pageSize")).toEqual("3");
141+
142+
req.flush({
143+
payload: findLessonsForCourse(12).slice(0,3)
144+
});
145+
146+
147+
});
121148

122149
afterEach(() => {
123150

0 commit comments

Comments
 (0)