Angularjs 等待范围评估量角器

Angularjs 等待范围评估量角器,angularjs,protractor,Angularjs,Protractor,考虑这个简单的量角器测试: <body> <div ng-app="test2App" ng-controller="test2Ctrl"> <input ng-model="myValue"> </div> </body> var test2App = angular.module('test2App', []) test2App.controller('test2Ctrl', function($

考虑这个简单的量角器测试:

<body>
    <div ng-app="test2App" ng-controller="test2Ctrl">
        <input ng-model="myValue">
    </div>
</body>


var test2App = angular.module('test2App', [])
test2App.controller('test2Ctrl', function($scope,$timeout) {
    $timeout(function() {
       $scope.myValue = true;
    },10000);
});

describe('my suite',function() {
    it('wait for a model to be defined',function() {
        element(by.model('myValue')).evaluate('myValue')
        .then(function(v) {
            expect(v).toBe(true);
        });
    });
});

var test2App=angular.module('test2App',[])
test2App.controller('test2Ctrl',函数($scope,$timeout){
$timeout(函数(){
$scope.myValue=true;
},10000);
});
描述('我的套件',函数(){
它('等待定义模型',函数(){
元素(按.model('myValue')).evaluate('myValue'))
.然后(函数(v){
期望(v)是真实的;
});
});
});
有没有一种方法比progrator sleep()函数更好地等待“myValue”加载到作用域中

thx

尝试浏览器。等待()

其中10000是以毫秒为单位的超时

browser.wait(function(){
  // Wait until condition is true.
  return element(by.model('myValue')).evaluate('myValue')
    .then(function(v) {
        // I'm not sure if it will evaluate to a string, try it.
        return v === 'true';
    });
}, 10000)