【问题标题】:Using Karma to scenario test an AngularJS controller?使用 Karma 对 AngularJS 控制器进行场景测试?
【发布时间】:2014-01-10 14:54:52
【问题描述】:

这是我尝试过的:

$ git clone https://github.com/angular/angular-seed my_project && cd my_project
$ rm -rf app update_angular.js test/e2e/scenarios.js
$ touch test/e2e/scenarios.js

然后我将AngularJS's official ngMock.$httpBackend docs 中的代码粘贴到:

test/e2e/scenarios.js

'use strict';                               // Line 1

function MyController($scope, $http) {...}  // Lines 3-22

describe('MyController', function() {...}   // Lines 24-87

错误

不幸的是,当我使用 config/karma-e2e.conf 运行测试时,我得到:

ReferenceError: inject is not defined at
                http://localhost:9876/base/test/e2e/scenarios.js?1387679134000:31

【问题讨论】:

    标签: angularjs karma-runner angularjs-controller angularjs-injector


    【解决方案1】:

    inject 在 angular-mocks 文件中定义,仅用于单元测试。如果您使用 Karma,只需将其添加到 files 数组中。

    e2e 测试位于浏览器之上,并由 angular-scenario 运行。你不能在那里注入任何 Angular 组件。

    顺便说一句,Angular 团队正在将他们的功能测试迁移到基于 Selenium 的 protractor。我会赶上那个而不是角度场景测试框架。量角器要好得多。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多