我正在使用 Yeoman 创建一个 Angular 项目并将模块定义为:
angular.module('angularApp')<br />
.controller('LogOutCtrl', function ($scope) {//do stuff});
通过 Yeoman 测试脚本如下:
describe('Controller: LogOutCtrl', function () {
// load the controller's module
beforeEach(module('angularApp', ['ui', 'appSettings']));
var LogOutCtrl,
scope;
// Initialize the controller and a mock scope
beforeEach(inject(function ($controller) {
scope = {};
LogOutCtrl = $controller('LogOutCtrl', {
$scope: scope
});
}));
it('should pass', function () {
expect(2+2).toBe(4); //aka some test
});
});
这通过 grunt/karma 作为错误返回:
Error: Argument 'fn' is not a function, got string
我还研究了一些其他的编写方法: How do I test an AngularJS service with Jasmine?
任何帮助将不胜感激,因为我是 Angular 和 Jasmine 测试的新手。我相信这可能是 Yeoman 测试脚本模板的问题。
谢谢!
最佳答案
这是 Yeoman 使用的模板的问题。从 1.0 beta 更新后,这些问题已得到解决。
关于AngularJS + Jasmine 测试脚本失败 fn 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16242568/