mercredi 22 avril 2015

How to test function in AngularJS service with mock data

How to create Jasmine unit test for one function in AngularJS service provider that has its own dependencies. I want to create mock data for myObject and test function getObjectShape() with that mock data. How to achieve that?

    (function () {
    'use strict';
    angular.module('objectShapes')
            .provider('shapesResolver', shapesResolver);

        function shapesResolver() {

            this.$get = function () {
                return resolver;
            };

            function resolver(myObject) {

                var service = {
                    getObjectShape: getObjectShape
                };

                function getObjectShape() {
                    return myObject.Shape;
                }
            }
        }
})();

Aucun commentaire:

Enregistrer un commentaire