感谢 mimo 的建议,我得出了最终的解决方案。
必须构造一个自定义的 dsl 语句,以欺骗expect
未来。
angular.scenario.dsl('expectScope', function() {
var _retrieve = function(source, target) {
if(target == '') return source;
var targets = target.split('.');
var nextTarget = targets[0];
return _retrieve(source[nextTarget], targets.splice(1).join('.') );
};
var chain = angular.extend({}, angular.scenario.matcher);
chain.not = function() {
this.inverse = true;
return chain;
};
return function(scope, name) {
this.future = new angular.scenario.Future('scope.'+name, function() {});
this.future.value = _retrieve(scope, name);
return chain;
};
});
通过调用scope.$digest
before expectScope(scope, 'value.othervalue')
,现在一切都按预期工作。