我尝试使用 Chutzpah + jasmine 来测试我的 AngularJS 代码。
这是我引用的文件
jasmine.js ver:1.3.1
jasmine-html.js
angular.min.js ver:1.2.0RC1
angular-mocks.js
alert.js
如果我不使用模板测试任何东西,它实际上会起作用。
我认为加载模板时一定有问题。
这是我尝试从 AngularJS UI Bootstrap 运行警报指令时的做法。
我没有在下面的测试中使用这种方式,因为它是针对 Karma runner 的。
beforeEach(module('template/alert/alert.html'));
我使用了与此不同的方法 post
beforeEach(inject(function ($templateCache) {
var directiveTemplate = null;
var req = new XMLHttpRequest();
req.onload = function () {
directiveTemplate = this.responseText;
};
req.open("get", "../../../template/alert/alert.html", false);
req.send();
$templateCache.put("template/alert/alert.html", directiveTemplate);
}));
它仍然有很多问题,但我认为模板已加载。
只通过了“如果没有指定关闭回调则不应显示关闭按钮”
大多数错误都是
TypeError: 'undefined' 不是一个函数(评估 'expect(alerts.eq(0)).toHaveClass('alert-success')')在....
似乎没有创建警报。
由于第一个错误是
Test 'alert:should generate alerts using ng-repeat' failed Expected 0 to equal 3.
有什么想法吗?
最佳答案
关于angularjs - 使用 Chutzpah + AngularJS + jasmine 测试指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18392125/