2014-11-25 66 views
3

我在AngularJS中有包含模块$文档的指令。

$document.click(function (e) {}); 

我一直尝试编写单元测试使用噶,它打破了测试,因为功能click()不存在$document,也尽量用$documentkeyup()等功能,并得到了同样的问题:

TypeError: undefined is not a function 

这是测试代码,这使得它失败:

describe('Directive: multiSelectMenu', function() { 

    var element, scope; 

    beforeEach(module('myApp')); 

    describe('Test setup', function() { 
     it ('Injecting required data', inject(function ($compile, $rootScope) { 
      scope = $rootScope.$new(); 
      element = $compile(angular.element('<div multi-select-menu></div>'))(scope); 

      $rootScope.$apply(); 

      scope = element.isolateScope(); 
      scope.$apply(); 
     })); 
    }); 
}); 

为什么它辉L·

回答

0

这里是the documentation说约$文件:

一个jQuery or jqLite包装为浏览器的window.document对象还。

如果你点击链接,你会看到在jqLit​​e元素上定义的方法。其中不包括click()而不是keyup()。这些方法确实存在于真正的jQuery对象上(请参阅http://api.jquery.com/category/events/),但AngularJS只会在您的js文件列表中包含jQuery,angular.js之前返回jQuery对象。

+0

但事件当我在Angular之前加载jQuery,在Karma上它看起来像$文件没有任何方法来空。 – 2014-11-26 08:49:08

相关问题