-1
我花了很多時間試圖弄清楚如何進入茉莉花的匿名函數。如何使用Jasmine/Javascript進行匿名功能
樣品的方法:
numerateColumns: function (rows) {
rows.each(function() {
var $row = $(this);
$row.children().each(function (index) {
var $cell = $(this);
$cell.addClass('column-' + (index + 1));
});
});
}
嘗試測試有:
it("[TEST] Should call each method.", function() {
// setup
var rows = {
each: function() {
return {
children: function() {
return {
replaceWith: function() {
return null;
}
};
}
};
}
};
spyOn(rows, 'each').and.callThrough();
// method under test
module.numerateColumns(rows);
// expectations
expect(rows.each).toHaveBeenCalled();
});
但覆蓋測試顯示我的方法的代碼僅在第一行(rows.each)被讀取。
如何強制它讀取裏面的所有代碼(function(){})?