【问题标题】:Jasmine test for angular directive: Actual is not a function角指令的茉莉花测试:实际不是函数
【发布时间】:2015-10-31 10:18:58
【问题描述】:

我有以下测试:

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 调用它就不再是一个函数,但是我如何测试我的指令是否编译成功?

【问题讨论】:

    标签: javascript angularjs unit-testing jasmine


    【解决方案1】:

    在进行更多修补之前,我很草率地问了这个问题。我所做的是将期望的内容包装在一个匿名函数调用中,如下所示:

    it("should load the directive without error", function () {
        expect(function() {
            $compile(inputElement)($scope)
        }).not.toThrow();
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多