3

我是 Angular 的新手。尝试编写我的应用程序 TDD 风格。我要做的是编写一个测试,它应该显示客户端的数量。为了让这个测试最初通过(没有注入东西),我只需将标记添加到 HTML <h1>Clients (3)</h1>

我想通过添加对何时有 2 个和 0 个客户端的检查来进一步扩展这个测试用例,但要做到这一点,我需要直接修改 E2E 测试中的范围,我不知道该怎么做。inject is not defined当我尝试时,我得到了,如下所示。

测试这个的正确方法是什么?

场景.js

describe('myApp', function() {

  describe('Client list view', function() {

    beforeEach(function() {
      browser().navigateTo('/');
    });

    // PASSES
    it('should display a list of clients', function() {
      expect(repeater('.clients li').count()).toBe(3);
    });

    // !!! TEST FAILS !!!
    it('should display the number of clients', inject(function($scope) {
      expect(element('h1').text()).toEqual('Clients (3)');
    }));
  });
});

控制器/客户端列表控制器.js

'use strict';

angular.module('forecastingApp').controller('ClientListCtrl', function($scope) {
  $scope.clients = [
    'Joe J.',
    'Brad C.',
    'Some Dude'
  ];
});
4

2 回答 2

5

目前,你不能。您可以使用injectJasmine 在单元测试中使用,但它不适用于 e2e 测试。

于 2013-08-01T21:47:09.350 回答
0

您介意向我们展示您的测试 html 吗?我想知道您的 html 中的脚本文件序列。是的。Scenario runner 必须使用 http 或 https 运行。或者您可以在单独的 html 中运行 e2e,格式如下:

<html lang="en">
<head>
<title>End2end Test Runner</title>
<meta charset="utf-8">
<base href="../..">
<script src="app/lib/angular/angular-scenario.js" ng-autotest></script>
<script src="test/e2e/scenarios.js"></script>
</head>
<body>
</body>
</html>

注意,你必须参考这个文件“angular-scenario.js”

于 2014-03-07T05:51:21.137 回答