Jasmine 测试用例:如何解析 locale.ready()

Jasmine testcase : How to resolve locale.ready()

我正在研究 AngularJs 1.5,刚开始使用 Jasmine 和 Karma 进行测试用例... 我的控制器使用

locale.ready('common').then(function () {
})

我无法模拟 'locale'。尽管它对于其他服务应该是直截了当的。 我为此在互联网上找到了一些东西,但文档没有工作代码:

'karma-json-preprocessor'

我能否获得演示如何在这种情况下模拟语言环境的示例代码?

编辑:(2017 年 5 月 29 日) 下面是示例代码: 承诺 returns 包含本地化键和值的对象:

angular.module('myApp', [])
    .controller('mytestcontroller', ['$scope', 'locale',
        function ($scope, locale) {
            locale.ready('common').then(function (res) {
                $scope.reportname = 'gauravreport';
            });
        }
    ]);

下面是我正在尝试的示例代码:

var scope, controller;
beforeEach(inject(function($controller, $rootScope, locale) {
        scope = $rootScope.$new();
        controller = $controller('mytestcontroller', {
            '$scope': scope,
            'locale': locale
        });
    }));
it('check report name', function(done) {
        var data = window.$json.$get('app/languages/en-US/home.lang.json');
        locale.ready('myreport')
            .then(function() {
                expect(scope.reportname).toBe("gauravreport");
                done();
            })
            .catch(done.fail);
    });

问题是当我 运行 这个测试时,它说 reportname 没有定义。似乎无法解析语言环境服务。

我已经使用此处所述的方法解决了这个问题:

Testing Promises with Jasmine - Provide and Spy