在如何处理此测试套件方面存在问题。我被要求在Bartender类的方法中实例化Beer类。
这是我的啤酒课:
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;
}
}我必须将一个Beer实例推入Bartender类的orders数组中,但我不确定如何处理。下面是我的Bartender类的代码:
class Bartender {
constructor(name, hourlyWage){
this.name = name;
this.hourlyWage = hourlyWage;
this.orders = [];
}
takeOrder(newOrder) {
var newOrder = new Beer;
this.orders.push(newOrder);
}
}在我的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)这是我不断失败的调酒师单元测试:
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如果有人有任何建议。谢谢。
发布于 2021-09-23 02:38:40
在您的代码中,takeOrder函数只有一个论点。所以只考虑了第一个论点,它是一个字符串。
您必须创建一个Beer实例并发送到函数takeOrder,如下所示
bartender.takeOrder(new Beer("Grand Teton Brewing", "Bitch Creek", "Brown Ale", 7, 16));
takeOrder(newOrder) {
this.orders.push(newOrder);
}或者编辑您的takeOrder函数以获得多个输入,并在takeOrder中调用Beer类的构造函数。
https://stackoverflow.com/questions/69293346
复制相似问题