Implementation of First Jasmine Specfication

Expectations are built with the function expect which takes a value, called the actual. It is chained with a Matcher function, which takes the expected value.

Each matcher implements a boolean comparison between the actual value and the expected value. It is responsible for reporting to Jasmine if the expectation is true or false. Jasmine will then pass or fail the spec.

import { CalculatorService } from './calculator.service';
import { LoggerService } from './logger.service';

describe('CalculatorService', () => {
    it('should add two numbers', () => {
        const calculator = new CalculatorService(new LoggerService());
        const result = calculator.add(2, 2);
        expect(result).toBe(4);
    });

    it('should substract two numbers', () => {
        const calculator = new CalculatorService(new LoggerService());
        const result = calculator.subtract(2, 2);
        expect(result).toBe(0, 'Wrong operation, please check it out');
    });
});

If we change the method logic for example:

subtract(n1: number, n2: number) {
    this.logger.log("Subtraction operation called");
    return n1 * n2; // CHANGE FROM '-' TO '*'
}

What we will see in the browser after running our npm test will be:

After fixing the bug in our code we will finally see the following lines, in the subtraction method we will modifying the '-' for the '*' we will see:

Last updated