2
如何測試Restangular.extendModel茉莉例如:Restangular extendModel茉莉花
控制器:
_this.populateSecurityGroups = function() {
var netid = _this.instance.vm_fields.cloud_network * 1;
CloudNetworksFactory.one(_this.provider, netid).then(
function (net) {
net.security_groups(_this.provider).then(
function (sgs) { _this.security_groups = sgs; },
function (err) {}
);
},
function (err) {}
);
};
廠:
var all = function (provider) {
return provider.getList('cloud_networks');
};
var one = function (provider, id) {
var defered = $q.defer();
this.all(provider).then(
function (nets) {
var res = _.find(nets.data, { id: id });
defered.resolve(res);
},
defered.reject
);
return defered.promise;
};
Restangular.extendModel('cloud_networks', function (model) {
model.security_groups = function (provider) {
var _this = this;
var defered = $q.defer();
provider.security_groups().then(
function (sgs) {
var res = ...
defered.resolve(res);
},
defered.reject
);
return defered.promise;
};
return model;
});
我無法測試這個功能,第一個錯誤是:
未定義不是(評價 'r.getList( 「cloud_networks」)')
未定義不是(評價 'e.security_groups')
這是開始時的對象的構造我的測試,我不能嘲笑restangular.extendModel:
it('should test populateCloudSubnets properly', function (done) {
ctrl.instance.vm_fields.cloud_network = 1;
ctrl.populateSecurityGroups().then(function(){
....
}, function(err){
expect(err).toBe(null);
done();
});
$httpBackend.flush();
});