。角1.2.24:测试指令抛出未定义范围$摘要(); [英] Angular 1.2.24: Testing directive throws undefined in scope.$digest();

查看:183
本文介绍了。角1.2.24:测试指令抛出未定义范围$摘要();的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚安装AngularJS 1.2.24,我想测试我的指令。在code看起来像如下:

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

然后,当我运行测试我的范围执行过程中会收到以下消息$消化()

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在浏览器中的变化有关。我比较previous版本,这似乎一个新的code给我。

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.

我试图恢复到我的previous工作版本1.2.21,一切工作正常。

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

难道我做错了吗?

推荐答案

原来,这是一个版本不匹配的角度嘲笑。我已经更新了我的角mocks.js 以这个这里和现在的一切工作正常。

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.

这篇关于。角1.2.24:测试指令抛出未定义范围$摘要();的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆