我正在尝试测试createGrant函数,并且我已经模拟了getGrant和getGroup函数;但是,我仍然遇到错误,因为从我的测试开始,showModal没有被解雇。
getGroup和getGrant都会返回一个promise,并且两个promise都必须在调用showModal之前解析。
提前感谢您的帮助。
-dj
$scope.createGrant = function(group) {
function showModal() {
$scope.activeGrant = {};
$scope.activeGroup = group;
myModal({
template: 'templates/edit-grant.tpl.html',
scope: $scope,
modalClass: 'edit-grant-modal'
});
}
var msg;
$q.all([grantService.getGrant(group.id).then(function(grantResponse) {
if (grantResponse) {
msg = {
message: '....',
classes: ['alert-danger']
};
}
}),
subscriberGroupService.getGroup(group).then(function(grpResponse) {
$scope.grpName = grpResponse.name
}, function() {
msg = {
message: '....',
classes: ['alert-danger']
};
}
)]).then(function(values) {
if (_.isUndefined(msg)) {
showModal();
}else{
notify(msg);
}
});
};
错误:
Expected undefined to equal { }.
Error: Expected undefined to equal { }.
at .<anonymous> (/....unit.spec.js:127:32)
Expected undefined to equal { id : 7 }.
Error: Expected undefined to equal { id : 7 }.
at .<anonymous> (/....unit.spec.js:128:32)
Expected spy myModalMock to have been called.
Error: Expected spy myModalMock to have been called.
at .<anonymous> (/....unit.spec.js:129:27)