문제

필자는 일부 사용 권한을 확인하고 사용 권한이 KO 인 경우 DOM에서 요소를 삭제하는 지시문을 코딩했습니다.

나는 그것을 테스트하고 싶습니다.하지만 ... 밑단, 나는이 간단한 테스트 작업을하기 위해 벽을 다시 쾅쾅 거리게합니다.

$ rootscope.digest ()를 사용하여 HTML을 컴파일합니다.이 기능을 호출 할 때 각도는 내 앱 메인 페이지를로드하려고 시도하고 두려운 "더 이상 요청하지 않음"오류가 발생합니다.

여기서는 테스트가 있습니다 :

describe('Unit testing permission-needed', function() {
    var $compile;
    var $rootScope;
    var $httpBackend;

    // Load the myApp module, which contains the directive
    beforeEach(module('app'));

    beforeEach(angular.mock.module('ngMockE2E'));

    beforeEach(inject(function(_$compile_, _$rootScope_, $injector) {
        $compile = _$compile_;
        $rootScope = _$rootScope_;
        $httpBackend = $injector.get('$httpBackend'); // not sur if I can inject it like others services ?
        $httpBackend.whenGET('app/login/login.tpl.html').passThrough(); // this doesn't seem to work

    }));



    it('should replace the element with the appropriate content', function() {



        // Compile a piece of HTML containing the directive
        var element = $compile("<div permission-needed><span>Some content goes here</span></div>")($rootScope);
        $rootScope.$digest(); // BAM => "no more request expected"

        // Do the test here
        // expect(....);
    });
});
.

사용하면 . 응답 ( '일부 HTML'); 대신에 .passthrough () 작동합니다.

고맙습니다.

도움이 되었습니까?

해결책

잘 답변 :

$ new () rootscope를 사용하여 테스트가 전달됩니다 :

$rootScope = _$rootScope_.$new();
.

이것은 누군가를 돕기를 바랍니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top