【发布时间】:2015-01-22 16:16:17
【问题描述】:
我正在尝试测试从以下状态的 onEnter 调用的 Angular UI Bootstrap 模式:
.state("profile.index.edit.services", {
url: "/edit/services/:serviceCode",
parent:"profile.index",
onEnter: ['$stateParams', '$state', '$modal',function($stateParams, $state, $modal) {
$modal.open({
templateUrl: 'profile/edit-services-modal.html',
controller: 'ProfileEditServicesController',
resolve: {
profileData: function(CacheService){
return CacheService.getItem(CacheService.Items.Profile.loadedProfile);
},
allServicesList: function(ProfileService){
return ProfileService.getAllServicesList($stateParams.serviceCode,$stateParams.orgId);
},
serviceCode: function() {
return $stateParams.serviceCode;
}
}
}).result.then(function(result) {
if (result) {
return $state.transitionTo("profile.index", { orgId: $stateParams.orgId });
}
else { // cancel
return $state.transitionTo("profile.index", { orgId: $stateParams.orgId }); // don't reload
}
}, function () {
// executes on close/cancel/ESC
return $state.transitionTo("profile.index", { orgId: $stateParams.orgId });
});
}]
})
我一直在努力反对这种尝试许多不同的方法来设置测试,但似乎无法弄清楚。非常感谢任何 plunkers 或建议!!!!
顺便说一句,上面的状态是这些状态的后代,我已经能够为该通道编写测试:
.state('profile.index', {
url: '/:orgId',
views: {
'profile-index@profile': {
templateUrl: 'profile/view-profile.html',
controller: 'ProfileController'
},
'header@': {
templateUrl: 'common/layout/header.html',
controller: 'HeaderController'
},
'footer@':{
templateUrl: 'common/layout/footer.html',
controller: 'FooterController'
}
},
resolve: {
profileData: function(ProfileService, $stateParams){
return ProfileService.getProfile($stateParams.orgId, true);
}
}
})
.state('profile.index.edit', {
url: '',
abstract: true
})
【问题讨论】:
标签: javascript angularjs unit-testing jasmine angular-ui-router