angularjs - How to write unit test to Restangular with Jasmine? -
i know how write test methods, other methods? put, patch, delete?
this example service method remove user:
removeone: function(user) { var deferred; console.log(user); deferred = $q.defer(); if (_.isundefined(user.id) || _.isnan(user.id)) { alertsserv.logerror(err); deferred.reject(err); } else { user.remove().then(function(result) { alertsserv.logsuccess('użytkownik został usunięty'); return deferred.resolve(result); }, function(err) { alertsserv.logerror(err); console.log(err); return deferred.reject(err); }); } return deferred.promise; }
it should this:
describe('delete /users/1', function() { beforeeach(function() { return $httpbackend.expect('delete', backend_url + '/users/1').respond(200, 'user1'); }); return describe('removeone method', function() { return it('should 1 user', function() { var user; user = { id: 1, routes: 'users' }; return userserv.removeone(user); }); }); });
but how define user?
p.s.: how define in jasmine/karma restangular base url?
now, more experience in unit testing, think should mock restangular , test if reastangular called arguments. shouldn't add $httpbackend in tests.
in unit tests, should check if services working good, not external libraries. right?
Comments
Post a Comment