Angular 1.2.24:测试指令在范围内抛出 undefined.$digest(); [英] Angular 1.2.24: Testing directive throws undefined in scope.$digest();
问题描述
我刚刚安装了 AngularJS 1.2.24,我正在尝试测试我的指令.代码如下所示:
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);
});
});
然后,当我运行测试时,我在 scope.$digest() 的执行过程中收到以下消息:
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
这似乎与浏览器中的 url 更改有关.我与以前的版本进行了比较,这对我来说似乎是一个新代码.
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.
我尝试恢复到我之前的工作版本 1.2.21,一切正常.
I tried to revert to my previous working version 1.2.21 and everything works fine.
我在这里做错了吗?
推荐答案
事实证明这是一个与 Angular 模拟不匹配的版本.我已经将我的 angular-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.
这篇关于Angular 1.2.24:测试指令在范围内抛出 undefined.$digest();的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!