aboutsummaryrefslogtreecommitdiffstats
path: root/test/service/invalidWidgetsSpec.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/service/invalidWidgetsSpec.js')
-rw-r--r--test/service/invalidWidgetsSpec.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/test/service/invalidWidgetsSpec.js b/test/service/invalidWidgetsSpec.js
new file mode 100644
index 00000000..b6b2da61
--- /dev/null
+++ b/test/service/invalidWidgetsSpec.js
@@ -0,0 +1,39 @@
+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);
+ });
+});