diff options
Diffstat (limited to 'test/BinderSpec.js')
| -rw-r--r-- | test/BinderSpec.js | 130 | 
1 files changed, 45 insertions, 85 deletions
| diff --git a/test/BinderSpec.js b/test/BinderSpec.js index a94e5eb2..84deca35 100644 --- a/test/BinderSpec.js +++ b/test/BinderSpec.js @@ -2,6 +2,8 @@  describe('Binder', function() { +  var element; +    function childNode(element, index) {      return jqLite(element[0].childNodes[index]);    } @@ -19,9 +21,8 @@ describe('Binder', function() {    });    afterEach(function() { -    if (this.element && this.element.dealoc) { -      this.element.dealoc(); -    } +    dealoc(element); +    dealoc(this.element);    });    it('BindUpdate', inject(function($rootScope, $compile) { @@ -42,60 +43,18 @@ describe('Binder', function() {    }));    it('ApplyTextBindings', inject(function($rootScope, $compile) { -    var element = $compile('<div ng:bind="model.a">x</div>')($rootScope); +    element = $compile('<div ng:bind="model.a">x</div>')($rootScope);      $rootScope.model = {a:123};      $rootScope.$apply();      expect(element.text()).toBe('123');    })); -  it('ReplaceBindingInTextWithSpan preserve surounding text', function() { -    expect(this.compileToHtml('<b>a{{b}}c</b>')).toBe('<b>a<span ng:bind="b"></span>c</b>'); -  }); - -  it('ReplaceBindingInTextWithSpan', function() { -    expect(this.compileToHtml('<b>{{b}}</b>')).toBe('<b><span ng:bind="b"></span></b>'); -  }); - -  it('BindingSpaceConfusesIE', inject(function($rootScope, $compile) { -    if (!msie) return; -    var span = document.createElement('span'); -    span.innerHTML = ' '; -    var nbsp = span.firstChild.nodeValue; -    expect(this.compileToHtml('<b>{{a}} {{b}}</b>')). -        toBe('<b><span ng:bind="a"></span><span>' + nbsp + '</span><span ng:bind="b"></span></b>'); -    dealoc(($rootScope)); -    expect(this.compileToHtml('<b>{{A}} x {{B}} ({{C}})</b>')). -        toBe('<b><span ng:bind="A"></span><span>' + nbsp + 'x </span><span ng:bind="B"></span>' + -             '<span>' + nbsp + '(</span><span ng:bind="C"></span>)</b>'); -  })); - -  it('BindingOfAttributes', inject(function($rootScope, $compile) { -    var element = $compile('<a href="http://s/a{{b}}c" foo="x"></a>')($rootScope); -    var attrbinding = element.attr('ng:bind-attr'); -    var bindings = fromJson(attrbinding); -    expect(decodeURI(bindings.href)).toBe('http://s/a{{b}}c'); -    expect(bindings.foo).toBeFalsy(); -  })); - -  it('MarkMultipleAttributes', inject(function($rootScope, $compile) { -    var element = $compile('<a href="http://s/a{{b}}c" foo="{{d}}"></a>')($rootScope); -    var attrbinding = element.attr('ng:bind-attr'); -    var bindings = fromJson(attrbinding); -    expect(bindings.foo).toBe('{{d}}'); -    expect(decodeURI(bindings.href)).toBe('http://s/a{{b}}c'); -  })); -    it('AttributesNoneBound', inject(function($rootScope, $compile) {      var a = $compile('<a href="abc" foo="def"></a>')($rootScope);      expect(a[0].nodeName).toBe('A');      expect(a.attr('ng:bind-attr')).toBeFalsy();    })); -  it('ExistingAttrbindingIsAppended', inject(function($rootScope, $compile) { -    var a = $compile('<a href="http://s/{{abc}}" ng:bind-attr="{\'b\':\'{{def}}\'}"></a>')($rootScope); -    expect(a.attr('ng:bind-attr')).toBe('{"b":"{{def}}","href":"http://s/{{abc}}"}'); -  })); -    it('AttributesAreEvaluated', inject(function($rootScope, $compile) {      var a = $compile('<a ng:bind-attr=\'{"a":"a", "b":"a+b={{a+b}}"}\'></a>')($rootScope);      $rootScope.$eval('a=1;b=2'); @@ -106,7 +65,7 @@ describe('Binder', function() {    it('InputTypeButtonActionExecutesInScope', inject(function($rootScope, $compile) {      var savedCalled = false; -    var element = $compile( +    element = $compile(        '<input type="button" ng:click="person.save()" value="Apply">')($rootScope);      $rootScope.person = {};      $rootScope.person.save = function() { @@ -117,8 +76,8 @@ describe('Binder', function() {    }));    it('InputTypeButtonActionExecutesInScope2', inject(function($rootScope, $compile) { -    var log = ''; -    var element = $compile('<input type="image" ng:click="action()">')($rootScope); +    var log = ""; +    element = $compile('<input type="image" ng:click="action()">')($rootScope);      $rootScope.action = function() {        log += 'click;';      }; @@ -129,7 +88,7 @@ describe('Binder', function() {    it('ButtonElementActionExecutesInScope', inject(function($rootScope, $compile) {      var savedCalled = false; -    var element = $compile('<button ng:click="person.save()">Apply</button>')($rootScope); +    element = $compile('<button ng:click="person.save()">Apply</button>')($rootScope);      $rootScope.person = {};      $rootScope.person.save = function() {        savedCalled = true; @@ -179,7 +138,7 @@ describe('Binder', function() {    }));    it('RepeaterContentDoesNotBind', inject(function($rootScope, $compile) { -    var element = $compile( +    element = $compile(        '<ul>' +          '<LI ng:repeat="item in model.items"><span ng:bind="item.a"></span></li>' +        '</ul>')($rootScope); @@ -198,8 +157,8 @@ describe('Binder', function() {    });    it('RepeaterAdd', inject(function($rootScope, $compile, $browser) { -    var element = $compile('<div><input type="text" ng:model="item.x" ng:repeat="item in items"></div>')($rootScope); -    $rootScope.items = [{x: 'a'}, {x: 'b'}]; +    element = $compile('<div><input type="text" ng:model="item.x" ng:repeat="item in items"></div>')($rootScope); +    $rootScope.items = [{x:'a'}, {x:'b'}];      $rootScope.$apply();      var first = childNode(element, 1);      var second = childNode(element, 2); @@ -213,7 +172,7 @@ describe('Binder', function() {    }));    it('ItShouldRemoveExtraChildrenWhenIteratingOverHash', inject(function($rootScope, $compile) { -    var element = $compile('<div><div ng:repeat="i in items">{{i}}</div></div>')($rootScope); +    element = $compile('<div><div ng:repeat="i in items">{{i}}</div></div>')($rootScope);      var items = {};      $rootScope.items = items; @@ -234,7 +193,7 @@ describe('Binder', function() {        $exceptionHandlerProvider.mode('log');      });      inject(function($rootScope, $exceptionHandler, $compile) { -      $compile('<div>{{error.throw()}}</div>', null, true)($rootScope); +      element = $compile('<div>{{error.throw()}}</div>', null, true)($rootScope);        var errorLogs = $exceptionHandler.errors;        $rootScope.error = { @@ -277,7 +236,7 @@ describe('Binder', function() {    });    it('NestedRepeater', inject(function($rootScope, $compile) { -    var element = $compile( +    element = $compile(        '<div>' +          '<div ng:repeat="m in model" name="{{m.name}}">' +             '<ul name="{{i}}" ng:repeat="i in m.item"></ul>' + @@ -290,21 +249,21 @@ describe('Binder', function() {      expect(sortedHtml(element)).toBe(          '<div>'+            '<#comment></#comment>'+ -          '<div name="a" ng:bind-attr="{"name":"{{m.name}}"}">'+ +          '<div name="a">'+              '<#comment></#comment>'+ -            '<ul name="a1" ng:bind-attr="{"name":"{{i}}"}"></ul>'+ -            '<ul name="a2" ng:bind-attr="{"name":"{{i}}"}"></ul>'+ +            '<ul name="a1"></ul>'+ +            '<ul name="a2"></ul>'+            '</div>'+ -          '<div name="b" ng:bind-attr="{"name":"{{m.name}}"}">'+ +          '<div name="b">'+              '<#comment></#comment>'+ -            '<ul name="b1" ng:bind-attr="{"name":"{{i}}"}"></ul>'+ -            '<ul name="b2" ng:bind-attr="{"name":"{{i}}"}"></ul>'+ +            '<ul name="b1"></ul>'+ +            '<ul name="b2"></ul>'+            '</div>' +          '</div>');    }));    it('HideBindingExpression', inject(function($rootScope, $compile) { -    var element = $compile('<div ng:hide="hidden == 3"/>')($rootScope); +    element = $compile('<div ng:hide="hidden == 3"/>')($rootScope);      $rootScope.hidden = 3;      $rootScope.$apply(); @@ -318,7 +277,7 @@ describe('Binder', function() {    }));    it('HideBinding', inject(function($rootScope, $compile) { -    var element = $compile('<div ng:hide="hidden"/>')($rootScope); +    element = $compile('<div ng:hide="hidden"/>')($rootScope);      $rootScope.hidden = 'true';      $rootScope.$apply(); @@ -337,7 +296,7 @@ describe('Binder', function() {    }));    it('ShowBinding', inject(function($rootScope, $compile) { -    var element = $compile('<div ng:show="show"/>')($rootScope); +    element = $compile('<div ng:show="show"/>')($rootScope);      $rootScope.show = 'true';      $rootScope.$apply(); @@ -357,7 +316,7 @@ describe('Binder', function() {    it('BindClass', inject(function($rootScope, $compile) { -    var element = $compile('<div ng:class="clazz"/>')($rootScope); +    element = $compile('<div ng:class="clazz"/>')($rootScope);      $rootScope.clazz = 'testClass';      $rootScope.$apply(); @@ -371,7 +330,7 @@ describe('Binder', function() {    }));    it('BindClassEvenOdd', inject(function($rootScope, $compile) { -    var element = $compile( +    element = $compile(        '<div>' +          '<div ng:repeat="i in [0,1]" ng:class-even="\'e\'" ng:class-odd="\'o\'"></div>' +        '</div>')($rootScope); @@ -387,7 +346,7 @@ describe('Binder', function() {    }));    it('BindStyle', inject(function($rootScope, $compile) { -    var element = $compile('<div ng:style="style"/>')($rootScope); +    element = $compile('<div ng:style="style"/>')($rootScope);      $rootScope.$eval('style={height: "10px"}');      $rootScope.$apply(); @@ -413,28 +372,29 @@ describe('Binder', function() {    });    it('ShoulIgnoreVbNonBindable', inject(function($rootScope, $compile) { -    var element = $compile( -      '<div>{{a}}' + -        '<div ng:non-bindable>{{a}}</div>' + -        '<div ng:non-bindable="">{{b}}</div>' + -        '<div ng:non-bindable="true">{{c}}</div>' + -      '</div>')($rootScope); +    element = $compile( +      "<div>{{a}}" + +        "<div ng:non-bindable>{{a}}</div>" + +        "<div ng:non-bindable=''>{{b}}</div>" + +        "<div ng:non-bindable='true'>{{c}}</div>" + +      "</div>")($rootScope);      $rootScope.a = 123;      $rootScope.$apply();      expect(element.text()).toBe('123{{a}}{{b}}{{c}}');    }));    it('ShouldTemplateBindPreElements', inject(function ($rootScope, $compile) { -    var element = $compile('<pre>Hello {{name}}!</pre>')($rootScope); -    $rootScope.name = 'World'; +    element = $compile('<pre>Hello {{name}}!</pre>')($rootScope); +    $rootScope.name = "World";      $rootScope.$apply(); -    expect(      sortedHtml(element)).toBe( -      '<pre ng:bind-template="Hello {{name}}!">Hello World!</pre>'); +    assertEquals( +      '<pre>Hello World!</pre>', +      sortedHtml(element));    }));    it('FillInOptionValueWhenMissing', inject(function($rootScope, $compile) { -    var element = $compile( +    element = $compile(          '<select ng:model="foo">' +            '<option selected="true">{{a}}</option>' +            '<option value="">{{b}}</option>' + @@ -458,7 +418,7 @@ describe('Binder', function() {    }));    it('DeleteAttributeIfEvaluatesFalse', inject(function($rootScope, $compile) { -    var element = $compile( +    element = $compile(        '<div>' +          '<input ng:model="a0" ng:bind-attr="{disabled:\'{{true}}\'}">' +          '<input ng:model="a1" ng:bind-attr="{disabled:\'{{false}}\'}">' + @@ -485,7 +445,7 @@ describe('Binder', function() {        $exceptionHandlerProvider.mode('log');      });      inject(function($rootScope, $exceptionHandler, $log, $compile) { -      var element = $compile( +      element = $compile(          '<div>' +            '<input type="button" ng:click="greeting=\'ABC\'"/>' +            '<input type="button" ng:click=":garbage:"/>' + @@ -505,7 +465,7 @@ describe('Binder', function() {    });    it('ItShouldSelectTheCorrectRadioBox', inject(function($rootScope, $compile) { -    var element = $compile( +    element = $compile(        '<div>' +          '<input type="radio" ng:model="sex" value="female">' +          '<input type="radio" ng:model="sex" value="male">' + @@ -527,7 +487,7 @@ describe('Binder', function() {    }));    it('ItShouldRepeatOnHashes', inject(function($rootScope, $compile) { -    var element = $compile( +    element = $compile(        '<ul>' +          '<li ng:repeat="(k,v) in {a:0,b:1}" ng:bind=\"k + v\"></li>' +        '</ul>')($rootScope); @@ -541,7 +501,7 @@ describe('Binder', function() {    }));    it('ItShouldFireChangeListenersBeforeUpdate', inject(function($rootScope, $compile) { -    var element = $compile('<div ng:bind="name"></div>')($rootScope); +    element = $compile('<div ng:bind="name"></div>')($rootScope);      $rootScope.name = '';      $rootScope.$watch('watched', 'name=123');      $rootScope.watched = 'change'; @@ -551,7 +511,7 @@ describe('Binder', function() {    }));    it('ItShouldHandleMultilineBindings', inject(function($rootScope, $compile) { -    var element = $compile('<div>{{\n 1 \n + \n 2 \n}}</div>')($rootScope); +    element = $compile('<div>{{\n 1 \n + \n 2 \n}}</div>')($rootScope);      $rootScope.$apply();      expect(element.text()).toBe('3');    })); | 
