我有一个10项函数的单元测试,它们都有一个自定义服务的inject
回调:
describe('Something', function() {
beforeEach(module('myApp'));
it('Foo == bar ?', inject(function(ctrl) {
expect(ctrl.foo).toEqual('Bar');
}));
// 10 other function with the same injection
});
是否有办法将这些注入分解到beaforeach
函数中?
var app = angular.module('myApp');
app.factory('ctrl', function(){
return {'foo': 'Bar'};
});
describe('Something', function() {
var control;
beforeEach(function() {
module('myApp');
inject(function(_ctrl_) {
control = _ctrl_;
});
//or can use $injector
/*inject(function($injector) {
control = $injector.get('ctrl');
});*/
});
it('Foo == bar ?', function() {
expect(control.foo).toEqual('Bar');
});
// 10 other functions will use control same as above
});