我在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?
答案 0 :(得分:0)
我不认为页面绑定有效,因为salutations
不在$scope
,您需要将其更改为
function MainCtrl($scope) {
$scope.salutations = [{
key: "male",
value: "Mr."
}, {
key: "female",
value: "Mrs."
}];
$scope.salutation = $scope.salutations[0];
}