【发布时间】:2017-02-03 01:38:14
【问题描述】:
我刚刚开始从 angular 1.48 -> 1.61 迁移 我留下了一个拒绝通过的单元测试。 我们要验证我们编写的指令将来不会更改,因此它始终保留在 require 属性中。
这是指令定义:
angular.module('ourApp')
.directive('ourdirective', ['$timeout', function($timeout) {
return {
restrict: 'AE',
require: 'ngModel',
scope: {
options:'=?',
max:'=',
ngModel : "="
},
templateUrl: 'ourhtmltemplate.html'
link: function(scope, elt, attrs, ctrl) { // some code here }
这是我们为此编写的单元测试。您可以假设没有任何类型的编译错误,并且其他测试非常顺利。
it('should throw if no ng model present', function() {
expect(function() {
buildElement("<ourdirective ></ourdirective>");
}).toThrowError();
};
function buildElement(html) {
element = angular.element(html);
$compile(element)($rootScope);
$rootScope.$digest();
$rootScope.select = {}
isolatedScope = element.isolateScope();
$rootScope.$apply(function() {});
}
我们正在使用以下软件包:
“角度”:“1.6.1”, “角度模拟”:“1.6.1”, “茉莉花期待”:“1.22”, "业力": "^0.12.31", “业力茉莉花”:“^0.3.5”, “业力茉莉花匹配器”:“^0.1.3”, "karma-phantomjs-launcher": "^0.1.4",
任何帮助都将是最合适的。
【问题讨论】:
标签: angularjs testing angularjs-directive karma-jasmine