测试角度和茉莉花的局部存储

时间:2015-10-06 12:12:26

标签: angularjs local-storage

我有以下LocalStorage工厂

    (function () {

  angular.module('xxxx.factories', [])

  .factory('$localstorage', ['$window', function($window) {
    return {
      set: function(key, value) {
        $window.localStorage[key] = value;
      },
      get: function(key, defaultValue) {
        return $window.localStorage[key] || defaultValue;
      },
      setObject: function(key, value) {
        $window.localStorage[key] = JSON.stringify(value);
      },
      getObject: function(key) {
        return JSON.parse($window.localStorage[key] || '{}');
      }
    }
  }]);

})();

我有我的茉莉花测试

    describe('Application Start Ctrl', function () {

    beforeEach(angular.mock.module('xxxx.controllers'));

    var $controller, $window;

    beforeEach(angular.mock.inject(function (_$controller_, _$window_) {
        $controller = _$controller_;
        $window = _$window_;
    }));


    describe('Register', function () {
        it('Application Started', function () {
            var $scope = {};
            var $inject = angular.injector(['xxxx.services', 'xxxx.factories']);
            var setupService = $inject.get('$SetupService');
            var localstorage = $inject.get('$localstorage');
            var controller = $controller('ApplicationStartCtrl', { $scope: $scope, $SetupService: setupService, $localstorage: localstorage });
            $scope.getstarted();
            expect($scope.started).toBe(true);
        });
    });


});

我收到以下错误:

未知提供商:$ windowProvider< - $ window< - $ localstorage

我可以看到我的工厂对$ window有依赖性。我只是想知道如何将它注入我的测试中。

0 个答案:

没有答案