mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-04-21 23:24:44 +00:00
40 lines
1,020 B
JavaScript
40 lines
1,020 B
JavaScript
|
|
describe('$invalidWidgets', function() {
|
||
|
|
var scope;
|
||
|
|
|
||
|
|
beforeEach(function(){
|
||
|
|
scope = angular.scope();
|
||
|
|
});
|
||
|
|
|
||
|
|
|
||
|
|
afterEach(function(){
|
||
|
|
dealoc(scope);
|
||
|
|
});
|
||
|
|
|
||
|
|
|
||
|
|
it("should count number of invalid widgets", function(){
|
||
|
|
scope = compile('<input name="price" ng:required ng:validate="number"></input>');
|
||
|
|
jqLite(document.body).append(scope.$element);
|
||
|
|
scope.$init();
|
||
|
|
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);
|
||
|
|
});
|
||
|
|
});
|