在團隊中使用qunit,我試圖弄清楚如何用qunit測試指令。我在下面的例子中https://egghead.io/lessons/angularjs-unit-testing-a-directive如何用qunit測試angularjs指令?
這裏的指令:
var app = angular.module("app", []);
app.directive("ehSimple", function() {
return function(scope, element) {
element.addClass("plain");
}
})
這裏是我的qunit測試到目前爲止
var injector = angular.injector(['ng', 'app']);
test('ehSimple directive', function() {
var element;
var $scope;
injector.invoke(['$compile', function($compile, $rootScope) {
$scope = $rootScope;
element = angular.element('<div eh-simple>{{ 2 + 2}}</div>');
$compile(element)($rootScope);
}]);
$scope.$digest();
console.log(element.html());
ok(element.html() == '4');
});
當我嘗試運行與卡拉測試我得到:
Died on test #1 @/home/.../tests/qunit/test_directives.js:34
: [ng:areq] Argument 'scope' is required
非常令人沮喪的任何想法?