我有以下测试:
it("should load the directive without error", function () {
expect($compile(inputElement)($scope)).not.toThrow();
});
并且我的输入元素包含我的指令。我的指令对 ngModel 有要求,测试的目的是如果指令所在的元素具有 ngModel 指令,则它可以无错误地编译。所有这些都在生产中有效,但由于某种原因我的测试失败了,我收到了消息:
Actual is not a Function in __pathToJasmine/jasmine.js (line 2207)
我也在使用 Jasmine 2.0。
现在,我意识到实际的函数是 $compile,一旦使用 $scope 调用它,它就不再是一个函数,但是我如何测试我的指令是否编译成功?
最佳答案
在进行更多修改之前我很鲁莽地问这个问题。我所做的是将 Expect 的内容包装在匿名函数调用中,如下所示:
it("should load the directive without error", function () {
expect(function() {
$compile(inputElement)($scope)
}).not.toThrow();
});
关于javascript - Angular Directive(指令) : Actual is not a function 的 Jasmine 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33450459/