angular.js/test/service/invalidWidgetsSpec.js
Igor Minar 945056b166 linking function should return bound scope
angular.compile()() returns {scope:scope, view:view},
this isn't useful at all and only makes tests more verbose.
Instead, this change makes the linking function return scope directly
and if anyone needs the linked dom there are two ways to do it
documented in angular.compile.

other changes:
- moved angular.compile docs to the compiler so that they are closer to
  the compiler
- fixed some typos and updated angular.compile docs with the new return
  value
2011-03-01 17:09:25 -08:00

39 lines
1 KiB
JavaScript

describe('$invalidWidgets', function() {
var scope;
beforeEach(function(){
scope = angular.scope();
});
afterEach(function(){
dealoc(scope);
});
it("should count number of invalid widgets", function(){
var element = jqLite('<input name="price" ng:required ng:validate="number"></input>')
jqLite(document.body).append(element);
scope = compile(element)();
var $invalidWidgets = scope.$service('$invalidWidgets');
expect($invalidWidgets.length).toEqual(1);
scope.price = 123;
scope.$eval();
expect($invalidWidgets.length).toEqual(0);
scope.$element.remove();
scope.price = 'abc';
scope.$eval();
expect($invalidWidgets.length).toEqual(0);
jqLite(document.body).append(scope.$element);
scope.price = 'abcd'; //force revalidation, maybe this should be done automatically?
scope.$eval();
expect($invalidWidgets.length).toEqual(1);
jqLite(document.body).html('');
scope.$eval();
expect($invalidWidgets.length).toEqual(0);
});
});