Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Testing 角度e2e测试-未捕获参考错误:未定义注入_Testing_Angularjs - Fatal编程技术网

Testing 角度e2e测试-未捕获参考错误:未定义注入

Testing 角度e2e测试-未捕获参考错误:未定义注入,testing,angularjs,Testing,Angularjs,我是个新手。正在尝试编写我的应用程序TDD样式。我要做的是为它编写一个测试,它应该显示客户端的数量。为了让这个测试在初始阶段通过(没有注入内容),我只需将标记添加到HTML客户机(3) 我想进一步扩展这个测试用例,在有2个和0个客户端时添加检查,但要做到这一点,我需要直接修改E2E测试中的范围,我不知道如何做到这一点。当我尝试时,我得到的注入未定义,如下所示 测试这个的正确方法是什么 scenarios.js describe('myApp', function() { describe(

我是个新手。正在尝试编写我的应用程序TDD样式。我要做的是为它编写一个测试,它应该显示客户端的数量。为了让这个测试在初始阶段通过(没有注入内容),我只需将标记添加到HTML
客户机(3)

我想进一步扩展这个测试用例,在有2个和0个客户端时添加检查,但要做到这一点,我需要直接修改E2E测试中的范围,我不知道如何做到这一点。当我尝试时,我得到的
注入未定义
,如下所示

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

scenarios.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)');
    }));
  });
});
'use strict';

angular.module('forecastingApp').controller('ClientListCtrl', function($scope) {
  $scope.clients = [
    'Joe J.',
    'Brad C.',
    'Some Dude'
  ];
});
控制器/客户端列表controller.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)');
    }));
  });
});
'use strict';

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

现在,你不能。您可以使用Jasmine在单元测试中使用
inject
,但它不适用于e2e测试。

您介意向我们展示您的测试html吗?我想知道脚本文件在html中的顺序。 对场景运行程序必须使用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>

End2end测试转轮

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

,如果需要,我们如何注入任何服务