だから私は次のものを持っています:
angular.module('common.lodash', []).factory('_', function() {
_.additionFunctionOnLodashThatICreated = function(foo, bar, baz) { ... };
return _;
});
私は別のモジュールで lodash に依存しています:
angular.module('common.gridhelper', ['common.lodash']).factory('gridhelper', function(_) {
var service;
service.foo = function (collection) {
// find is a native function on lodash
return _.find(...);
}
return service;
});
ブラウザでサイトに移動すると、すべてが「機能」します。ただし、いくつかのテストを作成しようとすると、さまざまな結果が得られます。
以下が機能するため、サービスにアクセスできることがわかります。
describe('Lodash Service:', function() {
beforeEach(module('common.lodash'));
it('should get an instance of the lodash factory', inject(function(_) {
expect(_).toBeDefined();
}));
});
ただし、これは失敗します:
describe('GridHelper Service:', function() {
var gh;
beforeEach(function () {
angular.module('test', [
'common.lodash',
'common.gridhelper'
]);
});
beforeEach(module('test'));
it('should return a good foo', inject(function(gridhelper) {
gridhelper.foo({'a': { 'b': 0 }});
});
エラーを返します:
TypeError: 'undefined' is not an object (evaluating '_.find(...)')
楽しみのために、gridhelper サービスで '_' を出力しようとしましたが、テストで実行すると null として表示されますが、ブラウザーで実行するとデータが入力されます。
私が行方不明になっている作品について考えている人はいますか?