Angular 1.2.24:测试指令在scope。$ digest();中引发未定义

艾伦·索扎(Alan Souza)

我刚刚安装了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);
    });
});

然后,当我运行测试时,在执行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

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

我试图恢复到以前的工作版本1.2.21,并且一切正常。

我在这里做错什么了吗?

艾伦·索扎(Alan Souza)

事实证明,这是Angular模拟的不匹配版本。我已经将我的angular-mocks.js更新此处的,现在一切正常。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章