3

모듈 $ document를 포함하는 AngularJS의 지시문이 있습니다. 나는 그것이 카르마를 사용하는 단위 테스트를 작성하려고하고 기능 click()keyup() 같은 $document의 다른 기능을 시도, $document에 존재하지 때문에 시험을 중단하고 같은 문제를 가지고있었습니다

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

:

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(); 
     })); 
    }); 
}); 

는 이유는 무엇입니까 그것을 FAI 엘?

답변

0

여기 the documentation에 $ 문서에 대한 말씀입니다 : 브라우저의 window.document 객체

jQuery or jqLite 래퍼.

링크를 클릭하면 jqLite 요소에 정의 된 메소드가 표시됩니다. keyup()이 아닌 click()도 그 중 하나입니다. 이러한 메소드는 실제 jQuery 객체 (http://api.jquery.com/category/events/ 참조)에 존재하지만 AngularJS는 JS 파일 목록에 angular.js보다 앞에 jQuery를 포함하면 jQuery 객체 만 반환합니다.

+0

하지만 Angular 이전에 jQuery를로드했을 때 카르마에서는 $ document가 아무런 메서드없이 비어있는 것처럼 보입니다. –

관련 문제