jeudi 1 septembre 2016

Recommended way to unit test an AngularJS factory utilising private variables

This basic AngularJS factory has get / set methods that interact with a private globals object. I'm looking for advice on how best to unit test this.

Changing globals to a public property feels like an anti-pattern to me.

angular.module('Shared')
    .factory('SoundGlobals', [

        function () {
            var globals = {};

            return {
                getGlobal: function (name) {
                    return globals[name];
                },

                setGlobal: function (name, value) {
                    globals[name] = value;
                }
            };
        }
    ]);

Aucun commentaire:

Enregistrer un commentaire