Is it possible to mock local variable in angularjs factory from karma?
<p>I have the below code:</p>

<pre><code>'use strict';

angular
    .module('testmodule')
    .factory('TestService', ['$q', '$timeout',
        function ($q, $timeout) {
</code></pre>

<blockquote>
  <p>var timeoutRetries = 0; // <strong>need to mock this from here</strong></p>
</blockquote>

<pre><code>            var api = new TestApi();

            function getResults(id, prevDeferred) {
                var deferred = prevDeferred || $q.defer();

                function handleSuccessResponse(data) {
                    if (data.status === 'ready') {
                        results.put(id, data);
                        deferred.resolve(data);
                    } else {                        
</code></pre>

<blockquote>
  <p>if (++timeoutRetries > 30) { // <strong>It wont get in here</strong></p>
</blockquote>

<pre><code>                            handleErrorResponse();
                        } else {
                            $timeout(function () {
                                getResults(id, deferred);
                            }, 2000);
                        }
                    }
                }

                function handleErrorResponse(response) {
                    deferred.reject(response);
                }

                if (results.get(id)) {
                    deferred.resolve(doSomething.get(id));
                    return deferred.promise;
                }

                api.get({id: id}).then(handleSuccessResponse, handleErrorResponse);
                return deferred.promise;
            }

            return {
                getResults: getResults
            };
        }]);
</code></pre>

<p>I am trying to mock the timeoutRetries entry from karma but i am not able to do it. Is it the ideal way of declaring it or should i want to move the variable to some function and update or which is the best way to mock it up from karma?</p>

<p>Tried with inject, declared the variable before calling the function. Still no success.  </p>