4

私は現在AngularJSを試しています。離れたデータから初期化される単純なサービスを作成しました。URL はアプリケーション値として渡されます。

//App declaration
angular.module('myApp', ['myApp.services']).value('someUrl', 'http://www.example.com');

//Service declaration
angular.module('myApp.services', ['someUrl']).factory('MyService', function(someUrl) {
    var data;
    "Do stuff"  
    return data;
});

現在、これを単体テストしようとしていますが、「someUrl」パラメーターを正しく設定できません。私はこのようなことを試しましたが、成功しませんでした:

angular.module('myApp', ['myApp.services']).value('someUrl', 'test/test.json');

describe('Services', function() {
    beforeEach(module('myApp.services'));

    describe('MyService', function() {
        it('should return {success: true}', inject(function() {
            expect(data).toEqual({success: true});
        }));
    });
});

ただし、常に「No module: someUrl」エラーが表示されます。単体テスト中にアプリの値を初期化する正しい構文は何ですか?

4

1 に答える 1