Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 367
Alan Souza Avatar asked Sep 11 '14 04:09

Alan Souza


1 Answers

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.

like image 90
Alan Souza Avatar answered Sep 27 '22 20:09

Alan Souza