经过3天的研究,我试图把拼图的各个部分放在一起,但没有成功。我试图对一个组件的控制器进行单元测试,并确保注入的服务将数据分配给一个数组。
我的组件是:
(x_i - x)(y_i - y)
我想测试ctrl.meals数组是否会正确填充数据,所以我写了以下测试:
(function () {
'use strict';
app.controller('MealSuggestionsController', MealSuggestionsController);
MealSuggestionsController.$inject = ['MealSuggestionsService'];
function MealSuggestionsController (MealSuggestionsService) {
var ctrl = this;
ctrl.meals = [];
function main () {
MealSuggestionsService.getMeals().then(
function (response) {
if (!response) {
return;
}
ctrl.meals = response.meals;
}
);
}
ctrl.$onInit = function () {
main();
};
}
app.component('mealSuggestions', {
transclude: true,
controller: 'MealSuggestionsController',
});
})();
我无法主要调用MealSuggestionsService.getMeals并检查分配的数据。