jeudi 31 décembre 2015

Angular unit-test - mocking method in controller

I need to mock the method of service in the controller. I know how to mock simple service like service.method, but not like this one. I dont know how to mock "action.user.update". If i tried to spy on it, i received an error 'Cannot read property 'update' of undefined'.

JsFidleDemo

My service:

.service('action', ['$http', '$q', function ($http, $q) {
    var service = {};

     service.user = {
        update: function (data, config) {
             return service.run({
                name: config.name,
                call: $http({
                    method: "POST",
                    url: "/user/edit",
                    data: data
                }),
                success: config.success,
                error: config.error
            });
        }
    };

    return service;
}]);

Aucun commentaire:

Enregistrer un commentaire