Skip to content

Commit 89f287a

Browse files
author
Your Name
committed
Angular Testing Course
1 parent 1d007e2 commit 89f287a

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('CalculatorService', () => {
2525

2626
});
2727

28-
fit('should add two numbers', () => {
28+
it('should add two numbers', () => {
2929

3030
console.log("add test");
3131

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

Lines changed: 30 additions & 4 deletions
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-
4+
import {COURSES} from '../../../../server/db-data';
55

66
describe('CoursesService', () => {
77

@@ -11,9 +11,11 @@ describe('CoursesService', () => {
1111
beforeEach(() => {
1212

1313
TestBed.configureTestingModule({
14-
providers: [
15-
CoursesService,
14+
imports: [
1615
HttpClientTestingModule
16+
],
17+
providers: [
18+
CoursesService
1719
]
1820
});
1921

@@ -24,8 +26,32 @@ describe('CoursesService', () => {
2426

2527
it('should retrieve all courses', () => {
2628

29+
coursesService.findAllCourses()
30+
.subscribe(courses => {
31+
32+
expect(courses).toBeTruthy('No courses returned');
33+
34+
expect(courses.length).toBe(12,
35+
"incorrect number of courses");
36+
37+
const course = courses.find(course => course.id == 12);
38+
39+
expect(course.titles.description).toBe(
40+
"Angular Testing Course");
41+
42+
});
43+
44+
const req = httpTestingController.expectOne('/api/courses');
45+
46+
expect(req.request.method).toEqual("GET");
47+
48+
req.flush({payload: Object.values(COURSES)});
49+
2750

2851
});
2952

3053

31-
});
54+
});
55+
56+
57+

0 commit comments

Comments
 (0)