我是Angular的新手.试着写我的应用程序TDD风格.我正在尝试做的是为它编写测试应该显示客户端的数量.为了让这个测试初始化(没有注入东西),我只需将标记添加到HTML中<h1>Clients (3)</h1>.
我想通过添加有2个和0个客户端的检查来进一步扩展这个测试用例,但为了做到这一点,我需要直接修改E2E测试中的范围,我不知道该怎么做.我inject is not defined尝试的时候,如下所示.
测试这个的正确方法是什么?
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)');
}));
});
});
Run Code Online (Sandbox Code Playgroud)
控制器/客户一览controller.js
'use strict';
angular.module('forecastingApp').controller('ClientListCtrl', function($scope) {
$scope.clients = [
'Joe J.',
'Brad C.',
'Some Dude'
];
});
Run Code Online (Sandbox Code Playgroud)