2

binding在 e2e 测试中测试 a 时遇到问题。这是我的代码:

HTML:

<select ng-model="salutation" ng-options="s.value for s in salutations">
  <option value="">Please choose</option>
</select>

控制器:

function MainCtrl($scope) {
  $scope.salutations = [{
    key: "male",
    value: "Mr."
  }, {
    key: "female",
    value: "Mrs."
  }];  
  $scope.salutation = salutations[0];
}

端到端测试:

...
describe('Form', function() {
  it('should initialize from model', function() {
    expect(binding('salutation')).toMatch('Mr.');
  }); 
});
...

运行 e2e 测试时,我收到以下错误消息:

select binding 'salutation'
Binding selector 'salutation' did not match.



<span>{{salutation}}</span>

谢谢!

更新:关闭以支持新问题为什么 binding() 在 e2e 测试中找不到双向绑定?

4

1 回答 1

0

我认为页面绑定不起作用,因为salutations不在$scope,您需要将其更改为

function MainCtrl($scope) {
    $scope.salutations = [{
        key: "male",
        value: "Mr."
    }, {
        key: "female",
        value: "Mrs."
    }];
    $scope.salutation = $scope.salutations[0];
}
于 2013-09-04T18:06:48.380 回答