次の機能を定義しました
Feature: Shoper can add an item to ShoppingCart
Scenario: First item added to ShoppingCart
Given I have an Empty ShoppingCart
When I add an Item to ShoppingCart
Then The ShoppingCart must have 1 item
Scenario: Second item added to ShoppingCart
Given I already have 1 item on my ShoppingCart
When I add a second item to ShoppingCart
Then The ShoppingCart must have 2 items
以下のように、CucumberJs を使用してステップ定義を生成しました。
'use strict';
module.exports = function () {
this.Given(/^I have an Empty ShoppingCart$/, function (callback) {
// Write code here that turns the phrase above into concrete actions
callback.pending();
});
this.When(/^I add an Item to ShoppingCart$/, function (callback) {
// Write code here that turns the phrase above into concrete actions
callback.pending();
});
this.Then(/^The ShoppingCart must have (\d+) item$/, function (arg1, callback) {
// Write code here that turns the phrase above into concrete actions
callback.pending();
});
}
しかし、監視可能なビューモデルのインスタンスを作成してそこでテストする方法が見つかりませんでした
function ShopCartViewModel() {
var self = this;
self.items = ko.observableArray([]);
self.grandTotal = ko.computed(function() {
var total = 0;
ko.utils.arrayForEach(this.items(), function(item) {
total += item.price();
});
return total.toFixed(2);
}, this);
self.getItemFromList = function ( id ) {
return ko.utils.arrayFirst(self.items(), function (item)
{
if (item.ProductId() === id()) {
return item;
}
});
}
}
ノックアウトをロードしようとしましたが、ビューモデルをロードした後:
var ko = require('../../js/knockout-3.1.0');
var ShopCart = require('../../js/shopCartViewModel');
var cart;
console.log('ko :', ko); // <-defined
console.log('cart :', ShopCart); // <- empty object {}
this.Given(/^I have an Empty ShoppingCart$/, function (callback) {
// Write code here that turns the phrase above into concrete actions
cart = new ShopCart(); // <- error
callback.pending();
});
ko は機能しましたが、ShopCart が返されます{}
ViewModel
内部 CucumberJs ステップ定義のインスタンスを作成するにはどうすればよい ですか?