aboutsummaryrefslogtreecommitdiffstats
path: root/test/service/invalidWidgetsSpec.js
blob: 027d8d7cba18ad64964ded7cafa285e0a4aed303 (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
40
41
'use strict';

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">');
    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);
  });
});