Created
June 19, 2019 10:35
-
-
Save MatLang/c8f5b7939b88e0718925f1cd44d39629 to your computer and use it in GitHub Desktop.
Service testing #testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('CalculatorService', () => { | |
let calculator: CalculatorService, | |
loggerSpy: any; | |
beforeEach(()=> { | |
console.log("Calling beforeEach"); | |
loggerSpy = jasmine.createSpyObj('LoggerService', ["log"]); | |
TestBed.configureTestingModule({ | |
providers: [ | |
CalculatorService, | |
{provide: LoggerService, useValue: loggerSpy} | |
] | |
}); | |
calculator = TestBed.get(CalculatorService); | |
}); | |
it('should add two numbers', () => { | |
console.log("add test"); | |
const result = calculator.add(2, 2); | |
expect(result).toBe(4); | |
expect(loggerSpy.log).toHaveBeenCalledTimes(1); | |
}); | |
it('should subtract two numbers', () => { | |
console.log("subtract test"); | |
const result = calculator.subtract(2, 2); | |
expect(result).toBe(0, "unexpected subtraction result"); | |
expect(loggerSpy.log).toHaveBeenCalledTimes(1); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment