Tener problemas sobre cómo abordar este conjunto de pruebas. Me piden que cree una instancia de la clase Beer dentro de un método en la clase Bartender. Quiero que mi método takeOrder admita múltiples entradas, por lo tanto, necesito llamar al constructor de la clase Beer dentro de takeOrder.
Esta es mi clase de cerveza:
constructor(newBeer) { this.brewer = newBeer.brewer; this.name = newBeer.name; this.type = newBeer.type; this.price = newBeer.price; this.volume = newBeer.volume; this.isFlat = false; } }Tengo que insertar una instancia de Beer en la matriz de pedidos en la clase Bartender y no estoy seguro de cómo acercarme. Aquí está mi código para la clase Bartender:
class Bartender { constructor(name, hourlyWage){ this.name = name; this.hourlyWage = hourlyWage; this.orders = []; } takeOrder(newOrder) { var newOrder = new Beer(); this.orders.push(newOrder); } }Sigo recibiendo este mensaje de error en mi prueba npm:
1) Bartender should be able to take orders: AssertionError: expected 'Grand Teton Brewing' to be an instance of Beer at Context.<anonymous> (test/bartender-test.js:33:12) at processImmediate (node:internal/timers:464:21)Esta es la prueba de unidad de camarero que sigo fallando:
it('should be able to take orders', function() { var bartender = new Bartender("Chaz", 8.50); bartender.takeOrder("Grand Teton Brewing", "Bitch Creek", "Brown Ale", 7, 16); assert.instanceOf(bartender.orders[0], Beer); assert.equal(bartender.orders.length, 1); assert.equal(bartender.orders[0].brewer, 'Grand Teton Brewing'); assert.equal(bartender.orders[0].name, 'Bitch Creek'); assert.equal(bartender.orders[0].type, 'Brown Ale'); assert.equal(bartender.orders[0].price, 7); assert.equal(bartender.orders[0].volume, 16); });Lmk si alguien tiene algún consejo. Gracias.
Hay dos problemas con su código.
Primero , la función bartender.takeOrder tiene un error. newOrder no se usó como argumento, sino que se volvió a declarar. Sugerir arreglo
takeOrder(newOrder) { this.order.push(new Beer(newOrder)) En segundo lugar , pasó el argumento incorrecto a bartender.takeOrder . Cuando ejecuta, solo se usó el primer argumento "Grand Teton Brewing" y el resto se descartó.
bartender.takeOrder("Grand Teton Brewing", "Bitch Creek", "Brown Ale", 7, 16);Sugerir arreglar, envolverlos en un objeto:
bartender.takeOrder({ brewer: 'Grand Teton Brewing', name: '', ... })