AngularJS + Jasmine 测试脚本失败 fn 不起作用

标签 angularjs jasmine yeoman karma-runner

我正在使用 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/

相关文章:

javascript - 我如何防止 bower 下载整个 repo 协议(protocol)

javascript - Angular2 模板应用程序

node.js - Yeoman Webapp 安装在 Windows 7 上失败(以及任何其他生成器)

javascript - 使用 angular-mocks.js 时,使用 Jasmine 进行的 AngularJS 测试无法调用 "angular.mock.module"

用于在非 SPA 站点上构建可重用组件的 Javascript MVC 框架

javascript - 将文件中的字符串转换为列表

javascript - 使用 Angular 模板生成可导出的 HTML

angularjs - 如何在 Jasmine 测试中触发window.onbeforeunload

javascript - Jasmine:如何测试 GET 请求中是否调用了正确的 URL

javascript - 更新 ng-if 变量后,Angular 显示空屏