Correctly fail tests if no binding matches and add better test cases for failure behavior.

This commit is contained in:
Elliott Sprehn 2010-10-27 17:56:44 -07:00
parent 62c0e5c460
commit 92e31b556f
2 changed files with 17 additions and 5 deletions

View file

@ -87,20 +87,20 @@ angular.scenario.dsl('using', function() {
*/
angular.scenario.dsl('binding', function() {
function contains(text, value) {
return text && text.indexOf(value) >=0;
return text && text.indexOf(value) >= 0;
}
return function(name) {
return this.addFutureAction("select binding '" + name + "'", function($window, $document, done) {
var elements = $document.elements('.ng-binding');
for ( var i = 0; i < elements.length; i++) {
var element = new elements.init(elements[i]);
if (contains(element.attr('ng:bind'), name) >= 0 ||
contains(element.attr('ng:bind-template'), name) >= 0) {
if (contains(element.attr('ng:bind'), name) ||
contains(element.attr('ng:bind-template'), name)) {
done(null, element.text());
return;
}
}
throw "Could not find binding: " + name;
done('Binding selector ' + name + ' did not match.');
});
};
});

View file

@ -271,7 +271,19 @@ describe("angular.scenario.dsl", function() {
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');
expect($root.futureError).toMatch(/did not match/);
});