0

我想在 AngularJS/Karma e2e 测试中检查字段值的字符串长度。我正在scenes.js 中尝试以下内容。错误消息指向第 178 行(见下文)第 52 列(“toBeGreaterThan”开始的地方):

expect(element('#userId').text().length).toBeGreaterThan(5);


TypeError: Cannot read property 'name' of undefined
    at Object.angular.scenario.matcher.(anonymous function) (http://web.loc/myApp/test/lib/angular/angular-scenario.js:24310:41)
    at Object.executeStatement (http://web.loc/myApp/test/lib/angular/angular-scenario.js:24276:30)
    at Object.chain.(anonymous function) [as toBeGreaterThan] (http://web.loc/myApp/test/lib/angular/angular-scenario.js:24284:37)
    at Object.<anonymous> (http://web.loc/myApp/test/e2e/scenarios.js:178:52)

如果我加载页面,我可以看到该字段填充了 userId。事实上,下面的所有字段都是通过控制器中的以下行从“用户”数组中填充的:

 $scope.users = response.data;

======== HTML ==========

 <div ng-repeat="user in users" class="users">
    <div class="inline pull-left">
        <label>Firstname: </label><span id="firstname">{{user.firstname}}</span><br/>
        <label>Lastname: </label><span id="lastname">{{user.lastname}}</span><br/>
        <label>Username: </label><span id="username">{{user.username}}</span><br/>
        <label>userEmail: </label><span id="email">{{user.email}}</span><br/>
        <label>Birthdate: </label><span id="dob">{{user.dob}}</span><br/>
        <label>User ID: </label><span id="userId">{{user.userId}}</span><br/>
        <label>Parent ID: </label><span id="parentId">{{user.parentId}}</span><br/>
        <label>Children: </label><span id="children">{{user.children}}</span><br/>
        <label>Type: </label><span id="type">{{user.type}}</span><br/>
        <label>Gender: </label><span id="gender">{{user.gender}}</span><br/>
        <label>Created Date:  </label><span id="createdDate">{{user.createdDate}}</span><br/>
        <label>Last LoginDate: </label><span id="lastLoginDate">{{user.lastLoginDate}}</span><br/>
        <label>Token: </label><span id="token">{{token}}</span><br/>
    </div>
    <div class="inline pull-right">
        <img ng-src="{{user.profilePictureUrl}}" class="profile-picture"/>
    </div>
</div>

======== 用户数组示例 ========

[{"type":"child","firstname":"Jane","lastname":"Sparrow","email":"jane@sparrow.com","password":"","username":" adam","dob":"1995-01-25","gender":"female","parentId":0,"userId":"999999","userToken":"xx-xxxxx-xxxx-xxxxx- xxxxxx","createdDate":"2013-08-12","lastLoginDate":"2013-08-13","profilePictureUrl":" http://zzz.com/profilepic/me.png ","children" :[]}]

4

0 回答 0