【发布时间】:2015-08-14 04:35:46
【问题描述】:
我有一个 AngularJS 指令,它从它的属性中读取输入数据,如下所示:
<my-directive input-data='items'></my-directive>
我的指令:
return {
scope: {
inputData: '='
}
}
...
现在,我通常在我的作用域中定义一个嵌套的对象数组,并且指令从我的作用域中读取该数据,但现在我试图让 jasmine、grunt 和 angular 与我的指令很好地配合,以便我可以测试它,但我收到了这个错误:
Error: [$compile:nonassign] Expression 'undefined' used with directive 'angularMultiSelect' is non-assignable!
这就是我尝试在我的 jasmine 测试中注入数据的方式:
inject(function($compile, $rootScope) {
scope = $rootScope.$new();
//scope.items = []; //<--- this works, but it's useless
scope.items = [{}, {}]; //<---- this triggers the error (I haven't deleted anything, that is an array with 2 empty objects
elem = angular.element(html);
$compile(elem)(scope);
scope.$digest();
});
我应该如何将我的数据从 jasmine 传递给我的指令?
【问题讨论】:
-
你能发布你在测试中编译的 HTML 吗?
-
@MichalCharemza 抱歉,O 忘了关闭问题。我的问题是该指令试图将另一个模型数据绑定到 jasmine 范围内不存在的变量。
标签: javascript angularjs gruntjs jasmine grunt-contrib-jasmine