我有一个指令,controller
函数调用了_.union
方法。
$scope.arr = _.union($scope.$parent.arr,$scope.$parent.DDC.arr);
当我运行我的测试用例时,由于上述行,所有测试用例都失败了。如果我注释掉上面这一行,一切都会过去。
以下是我的测试用例:
describe("directive: Testing Modules", function() {
// Suite for testing an individual piece of our feature.
describe('Test Directive', function() {
var $compile, scope, elm,directive;
module('app');
beforeEach(module('templates'));
beforeEach(function() {
inject(function(_$rootScope_, _$compile_) {
$compile = _$compile_;
scope = _$rootScope_.$new();
});
inject(function($compile) {
elm = $compile('<directive></directive>')(scope);
scope.$digest();
directive = elm.scope();
});
});
describe('key date list Directive Initialization Test cases', function(){
it('directive should exist', function(){
expect(directive).toBeDefined();
})
it('arr variable should exist', function(){
expect(directive.arr).toBeDefined();
})
it('arr variable should be type of boolean', function(){
expect(directive.arr).toEqual(jasmine.any(Object));
})
})
});
});
在我的karma.conf.js中,我已经包含在我的app.js之上。
'bower_components/ng-lodash/build/ng-lodash.min.js',