mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-09 07:14:44 +00:00
Correctly fail tests if no binding matches and add better test cases for failure behavior.
This commit is contained in:
parent
62c0e5c460
commit
92e31b556f
2 changed files with 17 additions and 5 deletions
|
|
@ -87,20 +87,20 @@ angular.scenario.dsl('using', function() {
|
||||||
*/
|
*/
|
||||||
angular.scenario.dsl('binding', function() {
|
angular.scenario.dsl('binding', function() {
|
||||||
function contains(text, value) {
|
function contains(text, value) {
|
||||||
return text && text.indexOf(value) >=0;
|
return text && text.indexOf(value) >= 0;
|
||||||
}
|
}
|
||||||
return function(name) {
|
return function(name) {
|
||||||
return this.addFutureAction("select binding '" + name + "'", function($window, $document, done) {
|
return this.addFutureAction("select binding '" + name + "'", function($window, $document, done) {
|
||||||
var elements = $document.elements('.ng-binding');
|
var elements = $document.elements('.ng-binding');
|
||||||
for ( var i = 0; i < elements.length; i++) {
|
for ( var i = 0; i < elements.length; i++) {
|
||||||
var element = new elements.init(elements[i]);
|
var element = new elements.init(elements[i]);
|
||||||
if (contains(element.attr('ng:bind'), name) >= 0 ||
|
if (contains(element.attr('ng:bind'), name) ||
|
||||||
contains(element.attr('ng:bind-template'), name) >= 0) {
|
contains(element.attr('ng:bind-template'), name)) {
|
||||||
done(null, element.text());
|
done(null, element.text());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw "Could not find binding: " + name;
|
done('Binding selector ' + name + ' did not match.');
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -271,7 +271,19 @@ describe("angular.scenario.dsl", function() {
|
||||||
expect($root.futureResult).toEqual('foo some baz');
|
expect($root.futureResult).toEqual('foo some baz');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return error if no binding exists', function() {
|
it('should match bindings by substring match', function() {
|
||||||
|
doc.append('<pre class="ng-binding" ng:bind="foo.bar() && test.baz() | filter">binding value</pre>');
|
||||||
|
$root.dsl.binding('test.baz');
|
||||||
|
expect($root.futureResult).toEqual('binding value');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return error if no bindings in document', function() {
|
||||||
|
$root.dsl.binding('foo.bar');
|
||||||
|
expect($root.futureError).toMatch(/did not match/);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return error if no binding matches', function() {
|
||||||
|
doc.append('<span class="ng-binding" ng:bind="foo">some value</span>');
|
||||||
$root.dsl.binding('foo.bar');
|
$root.dsl.binding('foo.bar');
|
||||||
expect($root.futureError).toMatch(/did not match/);
|
expect($root.futureError).toMatch(/did not match/);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue