Skip to content

Commit f153f29

Browse files
author
Your Name
committed
Angular Testing Course
1 parent 3b7b6d6 commit f153f29

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/app/courses/services/courses.service.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import {Injectable} from "@angular/core";
44
import {HttpClient, HttpParams} from "@angular/common/http";
55
import {Observable} from "rxjs/Observable";
6-
import {Course} from "../model/course";
76
import {map} from "rxjs/operators";
87
import {Lesson} from "../model/lesson";
8+
import {Course} from '../model/course';
99

1010

1111
@Injectable()
@@ -27,8 +27,8 @@ export class CoursesService {
2727
}
2828

2929

30-
saveCourse(courseId:number, changes: Partial<Course>) {
31-
return this.http.put(`/api/courses/${courseId}`, changes);
30+
saveCourse(courseId:number, changes: Partial<Course>): Observable<Course> {
31+
return this.http.put<Course>(`/api/courses/${courseId}`, changes);
3232
}
3333

3434
findLessons(

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

+19
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import {CoursesService} from './courses.service';
22
import {TestBed} from '@angular/core/testing';
33
import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing';
44
import {COURSES} from '../../../../server/db-data';
5+
import {Course} from '../model/course';
6+
57

68
describe('CoursesService', () => {
79

@@ -68,6 +70,23 @@ describe('CoursesService', () => {
6870

6971
});
7072

73+
74+
75+
it('should save the course data', () => {
76+
77+
const changes :Partial<Course> = {titles:{description: 'Testing Course'}};
78+
79+
coursesService.saveCourse(12, changes)
80+
.subscribe(course => {
81+
82+
expect(course.id).toBe(12);
83+
84+
});
85+
86+
});
87+
88+
89+
7190
afterEach(() => {
7291

7392
httpTestingController.verify();

0 commit comments

Comments
 (0)