Angular 1.2.24: Testing directive throws undefined in scope.$digest();

你离开我真会死。 提交于 2019-12-06 02:58:42

问题


I've just installed AngularJS 1.2.24 and I'm trying to test my directive. The code looks like follows:

describe('scenarios', function () {

    var scope, compile;

    beforeEach(module("app"));
    beforeEach(module("src/widgets/tt-header/header.html"));

    beforeEach(inject(function ($compile, $rootScope) {
        scope = $rootScope.$new();
        compile = $compile;
    }));

    function directive() {

        var el = angular.element('<div tt-header />');

        compile(el)(scope);
        scope.$digest();

        return el;
    }

    it('should load the directive', function () {

        var el = directive();

        expect(el).not.toBe(undefined);
    });
});

Then, when I run the test I get the following message during execution of scope.$digest():

PhantomJS 1.9.7 (Mac OS X) tt-header scenarios should load the tt-header directive FAILED
        TypeError: 'undefined' is not a function (evaluating '$browser.$$checkUrlChange()')
            at /Users/alansouza/tt-workspace/tt-app-angular/vendor/angular/angular.js:12502
            at ttHeader (/Users/alansouza/tt-workspace/tt-app-angular/tests/widgets/tt-header/tt-header-specs.js:20)
            at /Users/alansouza/tt-workspace/tt-app-angular/tests/widgets/tt-header/tt-header-specs.js:27

It seems to be something related to url changes in the browser. I compared to previous versions and this seems a new code to me.

I tried to revert to my previous working version 1.2.21 and everything works fine.

Am I doing something wrong here?


回答1:


It turns out that was a mismatched version with the Angular mocks. I've updated my angular-mocks.js to this one here and everything works fine now.



来源:https://stackoverflow.com/questions/25778938/angular-1-2-24-testing-directive-throws-undefined-in-scope-digest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!