绑定选择器'salutation'不匹配

时间:2013-09-04 15:41:22

标签: angularjs

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

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];
}

E2E测试:

...
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>

THX!

更新:关闭以支持新问题Why doesn't binding() find a two-way-binding in an e2e test?

1 个答案:

答案 0 :(得分:0)

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

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