我想我错过了什么。花了一些时间试图了解为什么我的测试不起作用。
编码。
angular.module('services')
.factory('UserPreferencesService', ['$resource', function ($resource)
{
return $resource('/rest/user-preferences/:id', {},
{ getById: { method: "GET", params: { id:'@id'}} });
}
]);
考试:
it('should get by Id', function() {
//given
var preferences = {language: "en"};
httpBackend.whenGET('/rest/user-preferences/1').respond(preferences);
//when
service.getById( {id:1} ).$promise.then(function(result) {
console.log("successssssssssssssssssssssssssssssssssssss");
//then
expect(result).toEqual(preferences);
}, function() {
console.log("something wrong");
})
});
它永远不会触发:“successssssssssssssssssssssssssssssssssss”。
我错过了什么?