vendredi 22 mars 2019

Javascript classes, using methods to past test

Im trying to create a method inside of my class to pass a test.

This is my class with a constructor

class Subscription {
  constructor() {
    this.customerName = "";
    this.nextShipDate = formatDate(dateFns.addMonths(new Date(), 1));
    this.intervalLength = 1;
    this.intervalUnit = "months";
    this.products = [];
  }

addProduct(){

}

};

What would I add to my method to get this test to pass?

  it("addProduct should add the productKey correctly", () => {
    const sub = new Subscription();
    sub.addProduct(1, "ABC-1", 123);

    const productKey = Object.keys(sub.products)[0];
    expect(productKey).toEqual(`1@@@ABC-1`);
    expect(sub.products[productKey]).toBeDefined();
    expect(sub.products[productKey].productId).toEqual(1);
    expect(sub.products[productKey].sku).toEqual("ABC-1");
    expect(sub.products[productKey].quantity).toEqual(123);
  });

Products in empty array so I don't know where to go from here.

Aucun commentaire:

Enregistrer un commentaire