Jasmine / Protractor ReferenceError:使用Angular + ngMocks定义了注入

时间:2015-01-22 17:48:44

标签: javascript angularjs dependency-injection jasmine protractor

我正在尝试使用角度模拟进行e2e测试,以便我可以注入$ cookies。我已将angular.js和angular-mocks.js文件添加到我的specRunner.html.jst文件中 - 位于bower_components / jasmine / grunt / templates中,这似乎很奇怪,因为我不使用grunt来运行这些测试 - 以及我仍然得到错误:

ReferenceError: inject is not defined

指向我的beforeEach块。

代码:

describe('The portfolio manager route', function () {

var testedId = '1';
var expect_tabs_len_start = 0;
var expect_tabs_len_end = 2;
var company_count = 0;
...

var _queries = {
    "company_tick": ["PFE", 1 ],
    "company_name": ["Cephalon", 1],
    "drugname_full": ["Ambien", 2],
    "drugname_generic": ["zolpidem", 5]
};

beforeEach(inject(function ($cookies) {
    $cookies['user_portfolio_name'] = 0;
}));

...

specRunner.html:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Jasmine Spec Runner v<%= jasmineVersion %></title>

  <link rel="shortcut icon" type="image/png" href="lib/jasmine-<%= jasmineVersion %>/jasmine_favicon.png">
  <link rel="stylesheet" href="lib/jasmine-<%= jasmineVersion %>/jasmine.css">

  <script src="lib/jasmine-<%= jasmineVersion %>/jasmine.js"></script>
  <script src="lib/jasmine-<%= jasmineVersion %>/jasmine-html.js"></script>
  <script src="lib/jasmine-<%= jasmineVersion %>/boot.js"></script>
  <script src="bower_components/angular/angular.js"></script>
  <script src="bower_components/angular-mocks/angular-mocks.js"></script>

  <!-- include source files here... -->
  <script src="src/Player.js"></script>
  <script src="src/Song.js"></script>

  <!-- include spec files here... -->
  <script src="spec/SpecHelper.js"></script>
  <script src="spec/PlayerSpec.js"></script>

</head>

<body>
</body>
</html>

0 个答案:

没有答案