Angular 1.2.24:测试指令在作用域中抛出未定义的$digest();

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

本文关键字:未定义 digest 测试 作用域 指令 Angular      更新时间:2023-09-26

我刚刚安装了AngularJS 1.2.24,正在尝试测试我的指令。代码如下:

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

然后,当我运行测试时,我在执行作用域期间得到以下消息$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

这似乎与浏览器中的url更改有关。我与以前的版本进行了比较,这对我来说似乎是一个新的代码。

我试着恢复到以前的工作版本1.2.21,一切都很好。

我是不是做错了什么?

事实证明,这是一个与Angular mock不匹配的版本。我已经在这里更新了我的angular mocks.js,现在一切都很好。