aboutsummaryrefslogtreecommitdiffstats
path: root/test/service/invalidWidgetsSpec.js
blob: b6b2da6176e303a9e41ad3c6a5e2badc9166acf4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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);
  });
});