Skip to content

Commit 3aefb13

Browse files
committed
Update calculator.service.spec.ts
1 parent 1602332 commit 3aefb13

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,19 @@ import { LoggerService } from "./logger.service";
55
describe("CalculatorService", () => {
66
// Specification
77
it("should add two number", () => {
8-
const calculator = new CalculatorService(new LoggerService());
8+
// creating a fake version of logger service by creating a new instance of it
9+
const logger = new LoggerService();
10+
11+
// jasmine will take the original spied object and beside calling the original functionality, it replaces the methods with a mock one instead of using it original one
12+
spyOn(logger, "log");
13+
14+
const calculator = new CalculatorService(logger);
915

1016
const result = calculator.add(2, 2);
1117

1218
expect(result).toBe(4);
19+
20+
expect(logger.log).toHaveBeenCalledTimes(1);
1321
});
1422

1523
// Specification

0 commit comments

Comments
 (0)