Skip to content

3 components #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Add spec for calculator service
  • Loading branch information
Ivan Muliarchyk committed Jan 3, 2020
commit 22fe8a6b42cd3633aef0bffabd3a5abe6ee12bc3
35 changes: 35 additions & 0 deletions src/app/courses/services/calculator.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { CalculatorService } from "./calculator.service";
import { TestBed } from "@angular/core/testing";
import { LoggerService } from "./logger.service";

describe('CalculatorService', () => {
let calculator: CalculatorService,
loggerSpy: any;

beforeEach(() => {
loggerSpy = jasmine.createSpyObj('LoggerService', ['log']);
TestBed.configureTestingModule({
providers: [
CalculatorService,
{provide: LoggerService, useValue: loggerSpy}
]
});

calculator = TestBed.get(CalculatorService);
});

it('should add two numbers', () => {
const result = calculator.add(2, 3);

expect(result).toBe(5);
expect(loggerSpy.log).toHaveBeenCalledTimes(1);
});

it('should subtract two numbers', () => {
const result = calculator.subtract(4, 3);

expect(result).toBe(1, 'unexpected subtraction result');
expect(loggerSpy.log).toHaveBeenCalledTimes(1);
});

});