dimanche 5 août 2018

How do I test a method in a typescript?

Tell me, how do I test the distanceCalculation () method? I want to check the accuracy of the result in the test with precisely specified values. How in the Jest to test the methods of the Typescript? This is a test task and I'm just learning.

class Car {
  amountOfFuel: number;
  fuelСonsumption: number;

    constructor(carAmountOfFuel: number,
      carFuelСonsumption: number) {
        this.amountOfFuel = carAmountOfFuel;
        this.fuelСonsumption = carFuelСonsumption;
      }

      distanceСalculation(): number {
        return (this.amountOfFuel / this.fuelСonsumption)*100;
    }
}

export class Bentley extends Car {
  }

export class Zhiguli extends Car {
  }

test code

import { Bentley, Zhiguli } from './sum'

test("property check Bentley", () => {
  let car1 = new Bentley(90, 12);

  expect(car1).toHaveProperty('amountOfFuel',90);
  expect(car1).toHaveProperty('fuelСonsumption', 12);
});

test("property check Zhiguli", () => {
  let car2 = new Zhiguli(40, 10);

  expect(car2).toHaveProperty('amountOfFuel',40);
  expect(car2).toHaveProperty('fuelСonsumption', 10);
});

Aucun commentaire:

Enregistrer un commentaire