diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/AngularSpec.js | 49 | ||||
| -rw-r--r-- | test/BinderSpec.js | 130 | ||||
| -rw-r--r-- | test/ScenarioSpec.js | 13 | ||||
| -rw-r--r-- | test/directivesSpec.js | 247 | ||||
| -rw-r--r-- | test/markupSpec.js | 72 | ||||
| -rw-r--r-- | test/sanitizerSpec.js | 10 | ||||
| -rw-r--r-- | test/scenario/dslSpec.js | 82 | ||||
| -rw-r--r-- | test/service/filter/filtersSpec.js | 16 | ||||
| -rw-r--r-- | test/service/logSpec.js | 2 | ||||
| -rw-r--r-- | test/testabilityPatch.js | 16 | ||||
| -rw-r--r-- | test/widget/inputSpec.js | 79 | ||||
| -rw-r--r-- | test/widget/selectSpec.js | 4 | ||||
| -rw-r--r-- | test/widgetsSpec.js | 94 | 
13 files changed, 397 insertions, 417 deletions
| diff --git a/test/AngularSpec.js b/test/AngularSpec.js index 2d469698..10f5fd2a 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -1,6 +1,12 @@  'use strict';  describe('angular', function() { +  var element; + +  afterEach(function(){ +    dealoc(element); +  }); +    describe('case', function() {      it('should change case', function() {        expect(lowercase('ABC90')).toEqual('abc90'); @@ -382,28 +388,6 @@ describe('angular', function() {    }); -  describe('directive', function() { -    it('should register directives with case-insensitive id', inject(function($compile) { -      angularDirective('ALLCAPS', function(val, el) {el.text('+' + val + '+')}); -      angularDirective('lowercase', function(val, el) {el.text('-' + val + '-')}); - -      var el = jqLite('<div>' + -                        '<span allcaps="xx1"></span>' + -                        '<span ALLcaps="xx2"></span>' + -                        '<span ALLCAPS="xx3"></span>' + -                        '<span lowerCASE="XX4">xx4</span>' + -                      '</div>'); -      $compile(el); -      expect(lowercase(sortedHtml(el))).toBe('<div>' + -                                                '<span allcaps="xx1">+xx1+</span>' + -                                                '<span allcaps="xx2">+xx2+</span>' + -                                                '<span allcaps="xx3">+xx3+</span>' + -                                                '<span lowercase="xx4">-xx4-</span>' + -                                              '</div>'); -    })); -  }); - -    describe('isDate', function() {      it('should return true for Date object', function() {        expect(isDate(new Date())).toBe(true); @@ -420,7 +404,7 @@ describe('angular', function() {    describe('compile', function() {      it('should link to existing node and create scope', inject(function($rootScope, $compile) {        var template = angular.element('<div>{{greeting = "hello world"}}</div>'); -      $compile(template)($rootScope); +      element = $compile(template)($rootScope);        $rootScope.$digest();        expect(template.text()).toEqual('hello world');        expect($rootScope.greeting).toEqual('hello world'); @@ -428,7 +412,7 @@ describe('angular', function() {      it('should link to existing node and given scope', inject(function($rootScope, $compile) {        var template = angular.element('<div>{{greeting = "hello world"}}</div>'); -      $compile(template)($rootScope); +      element = $compile(template)($rootScope);        $rootScope.$digest();        expect(template.text()).toEqual('hello world');      })); @@ -436,15 +420,15 @@ describe('angular', function() {      it('should link to new node and given scope', inject(function($rootScope, $compile) {        var template = jqLite('<div>{{greeting = "hello world"}}</div>'); -      var templateFn = $compile(template); +      var compile = $compile(template);        var templateClone = template.clone(); -      var element = templateFn($rootScope, function(clone){ +      element = compile($rootScope, function(clone){          templateClone = clone;        });        $rootScope.$digest(); -      expect(template.text()).toEqual(''); +      expect(template.text()).toEqual('{{greeting = "hello world"}}');        expect(element.text()).toEqual('hello world');        expect(element).toEqual(templateClone);        expect($rootScope.greeting).toEqual('hello world'); @@ -452,9 +436,9 @@ describe('angular', function() {      it('should link to cloned node and create scope', inject(function($rootScope, $compile) {        var template = jqLite('<div>{{greeting = "hello world"}}</div>'); -      var element = $compile(template)($rootScope, noop); +      element = $compile(template)($rootScope, noop);        $rootScope.$digest(); -      expect(template.text()).toEqual(''); +      expect(template.text()).toEqual('{{greeting = "hello world"}}');        expect(element.text()).toEqual('hello world');        expect($rootScope.greeting).toEqual('hello world');      })); @@ -524,4 +508,11 @@ describe('angular', function() {        expect(startingTag('<ng:abc x="2"><div>text</div></ng:abc>')).toEqual('<ng:abc x="2">');      });    }); + +  describe('snake_case', function(){ +    it('should convert to snake_case', function() { +      expect(snake_case('ABC')).toEqual('a_b_c'); +      expect(snake_case('alanBobCharles')).toEqual('alan_bob_charles'); +    }); +  });  }); 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');    })); diff --git a/test/ScenarioSpec.js b/test/ScenarioSpec.js index 986e2121..2070d301 100644 --- a/test/ScenarioSpec.js +++ b/test/ScenarioSpec.js @@ -1,23 +1,30 @@  'use strict';  describe("ScenarioSpec: Compilation", function() { +  var element; + +  afterEach(function() { +    dealoc(element); +  }); + +    describe('compilation', function() {      it("should compile dom node and return scope", inject(function($rootScope, $compile) {        var node = jqLite('<div ng:init="a=1">{{b=a+1}}</div>')[0]; -      $compile(node)($rootScope); +      element = $compile(node)($rootScope);        $rootScope.$digest();        expect($rootScope.a).toEqual(1);        expect($rootScope.b).toEqual(2);      }));      it("should compile jQuery node and return scope", inject(function($rootScope, $compile) { -      var element = $compile(jqLite('<div>{{a=123}}</div>'))($rootScope); +      element = $compile(jqLite('<div>{{a=123}}</div>'))($rootScope);        $rootScope.$digest();        expect(jqLite(element).text()).toEqual('123');      }));      it("should compile text node and return scope", inject(function($rootScope, $compile) { -      var element = $compile('<div>{{a=123}}</div>')($rootScope); +      element = $compile('<div>{{a=123}}</div>')($rootScope);        $rootScope.$digest();        expect(jqLite(element).text()).toEqual('123');      })); diff --git a/test/directivesSpec.js b/test/directivesSpec.js index 5bd5f5bd..9dee4860 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -1,6 +1,16 @@  'use strict';  describe("directive", function() { +  var element; + +  beforeEach(function() { +    element = null; +  }); + +  afterEach(function() { +    dealoc(element); +  }); +    var $filterProvider, element; @@ -19,7 +29,7 @@ describe("directive", function() {    describe('ng:bind', function() {      it('should set text', inject(function($rootScope, $compile) { -      var element = $compile('<div ng:bind="a"></div>')($rootScope); +      element = $compile('<div ng:bind="a"></div>')($rootScope);        expect(element.text()).toEqual('');        $rootScope.a = 'misko';        $rootScope.$digest(); @@ -28,47 +38,40 @@ describe("directive", function() {      }));      it('should set text to blank if undefined', inject(function($rootScope, $compile) { -      var element = $compile('<div ng:bind="a"></div>')($rootScope); +      element = $compile('<div ng:bind="a"></div>')($rootScope);        $rootScope.a = 'misko';        $rootScope.$digest();        expect(element.text()).toEqual('misko');        $rootScope.a = undefined;        $rootScope.$digest();        expect(element.text()).toEqual(''); +      $rootScope.a = null; +      $rootScope.$digest(); +      expect(element.text()).toEqual('');      }));      it('should set html', inject(function($rootScope, $compile) { -      var element = $compile('<div ng:bind="html|html"></div>')($rootScope); +      element = $compile('<div ng:bind-html="html"></div>')($rootScope);        $rootScope.html = '<div unknown>hello</div>';        $rootScope.$digest();        expect(lowercase(element.html())).toEqual('<div>hello</div>');      }));      it('should set unsafe html', inject(function($rootScope, $compile) { -      var element = $compile('<div ng:bind="html|html:\'unsafe\'"></div>')($rootScope); +      element = $compile('<div ng:bind-html-unsafe="html"></div>')($rootScope);        $rootScope.html = '<div onclick="">hello</div>';        $rootScope.$digest();        expect(lowercase(element.html())).toEqual('<div onclick="">hello</div>');      })); -    it('should set element element', inject(function($rootScope, $compile) { -      $filterProvider.register('myElement', valueFn(function() { -        return jqLite('<a>hello</a>'); -      })); -      var element = $compile('<div ng:bind="0|myElement"></div>')($rootScope); -      $rootScope.$digest(); -      expect(lowercase(element.html())).toEqual('<a>hello</a>'); -    })); - -      it('should suppress rendering of falsy values', inject(function($rootScope, $compile) { -      var element = $compile('<div>{{ null }}{{ undefined }}{{ "" }}-{{ 0 }}{{ false }}</div>')($rootScope); +      element = $compile('<div>{{ null }}{{ undefined }}{{ "" }}-{{ 0 }}{{ false }}</div>')($rootScope);        $rootScope.$digest();        expect(element.text()).toEqual('-0false');      }));      it('should render object as JSON ignore $$', inject(function($rootScope, $compile) { -      var element = $compile('<div>{{ {key:"value", $$key:"hide"}  }}</div>')($rootScope); +      element = $compile('<div>{{ {key:"value", $$key:"hide"}  }}</div>')($rootScope);        $rootScope.$digest();        expect(fromJson(element.text())).toEqual({key:'value'});      })); @@ -76,27 +79,15 @@ describe("directive", function() {    describe('ng:bind-template', function() {      it('should ng:bind-template', inject(function($rootScope, $compile) { -      var element = $compile('<div ng:bind-template="Hello {{name}}!"></div>')($rootScope); +      element = $compile('<div ng:bind-template="Hello {{name}}!"></div>')($rootScope);        $rootScope.name = 'Misko';        $rootScope.$digest();        expect(element.hasClass('ng-binding')).toEqual(true);        expect(element.text()).toEqual('Hello Misko!');      })); -    it('should have $element set to current bind element', inject(function($rootScope, $compile) { -      var innerText; -      $filterProvider.register('myFilter', valueFn(function(text) { -        innerText = innerText || this.$element.text(); -        return text; -      })); -      var element = $compile('<div>before<span ng:bind-template="{{\'HELLO\'|myFilter}}">INNER</span>after</div>')($rootScope); -      $rootScope.$digest(); -      expect(element.text()).toEqual("beforeHELLOafter"); -      expect(innerText).toEqual('INNER'); -    })); -      it('should render object as JSON ignore $$', inject(function($rootScope, $compile) { -      var element = $compile('<pre>{{ {key:"value", $$key:"hide"}  }}</pre>')($rootScope); +      element = $compile('<pre>{{ {key:"value", $$key:"hide"}  }}</pre>')($rootScope);        $rootScope.$digest();        expect(fromJson(element.text())).toEqual({key:'value'});      })); @@ -105,39 +96,40 @@ describe("directive", function() {    describe('ng:bind-attr', function() {      it('should bind attributes', inject(function($rootScope, $compile) { -      var element = $compile('<div ng:bind-attr="{src:\'http://localhost/mysrc\', alt:\'myalt\'}"/>')($rootScope); +      element = $compile('<div ng:bind-attr="{src:\'http://localhost/mysrc\', alt:\'myalt\'}"/>')($rootScope);        $rootScope.$digest();        expect(element.attr('src')).toEqual('http://localhost/mysrc');        expect(element.attr('alt')).toEqual('myalt');      }));      it('should not pretty print JSON in attributes', inject(function($rootScope, $compile) { -      var element = $compile('<img alt="{{ {a:1} }}"/>')($rootScope); +      element = $compile('<img alt="{{ {a:1} }}"/>')($rootScope);        $rootScope.$digest();        expect(element.attr('alt')).toEqual('{"a":1}');      })); -  }); -  it('should remove special attributes on false', inject(function($rootScope, $compile) { -    var element = $compile('<input ng:bind-attr="{disabled:\'{{disabled}}\', readonly:\'{{readonly}}\', checked:\'{{checked}}\'}"/>')($rootScope); -    var input = element[0]; -    expect(input.disabled).toEqual(false); -    expect(input.readOnly).toEqual(false); -    expect(input.checked).toEqual(false); - -    $rootScope.disabled = true; -    $rootScope.readonly = true; -    $rootScope.checked = true; -    $rootScope.$digest(); - -    expect(input.disabled).toEqual(true); -    expect(input.readOnly).toEqual(true); -    expect(input.checked).toEqual(true); -  })); +    it('should remove special attributes on false', inject(function($rootScope, $compile) { +      element = $compile('<input ng:bind-attr="{disabled:\'{{disabled}}\', readonly:\'{{readonly}}\', checked:\'{{checked}}\'}"/>')($rootScope); +      var input = element[0]; +      expect(input.disabled).toEqual(false); +      expect(input.readOnly).toEqual(false); +      expect(input.checked).toEqual(false); + +      $rootScope.disabled = true; +      $rootScope.readonly = true; +      $rootScope.checked = true; +      $rootScope.$digest(); + +      expect(input.disabled).toEqual(true); +      expect(input.readOnly).toEqual(true); +      expect(input.checked).toEqual(true); +    })); + +  });    describe('ng:click', function() {      it('should get called on a click', inject(function($rootScope, $compile) { -      var element = $compile('<div ng:click="clicked = true"></div>')($rootScope); +      element = $compile('<div ng:click="clicked = true"></div>')($rootScope);        $rootScope.$digest();        expect($rootScope.clicked).toBeFalsy(); @@ -146,14 +138,12 @@ describe("directive", function() {      }));      it('should stop event propagation', inject(function($rootScope, $compile) { -      var element = $compile('<div ng:click="outer = true"><div ng:click="inner = true"></div></div>')($rootScope); +      element = $compile('<div ng:click="outer = true"><div ng:click="inner = true"></div></div>')($rootScope);        $rootScope.$digest();        expect($rootScope.outer).not.toBeDefined();        expect($rootScope.inner).not.toBeDefined(); -      var innerDiv = element.children()[0]; - -      browserTrigger(innerDiv, 'click'); +      browserTrigger(element.find('div'), 'click');        expect($rootScope.outer).not.toBeDefined();        expect($rootScope.inner).toEqual(true);      })); @@ -162,7 +152,7 @@ describe("directive", function() {    describe('ng:submit', function() {      it('should get called on form submit', inject(function($rootScope, $compile) { -      var element = $compile('<form action="" ng:submit="submitted = true">' + +      element = $compile('<form action="" ng:submit="submitted = true">' +          '<input type="submit"/>' +          '</form>')($rootScope);        $rootScope.$digest(); @@ -175,7 +165,7 @@ describe("directive", function() {    describe('ng:class', function() {      it('should add new and remove old classes dynamically', inject(function($rootScope, $compile) { -      var element = $compile('<div class="existing" ng:class="dynClass"></div>')($rootScope); +      element = $compile('<div class="existing" ng:class="dynClass"></div>')($rootScope);        $rootScope.dynClass = 'A';        $rootScope.$digest();        expect(element.hasClass('existing')).toBe(true); @@ -196,7 +186,7 @@ describe("directive", function() {      it('should support adding multiple classes via an array', inject(function($rootScope, $compile) { -      var element = $compile('<div class="existing" ng:class="[\'A\', \'B\']"></div>')($rootScope); +      element = $compile('<div class="existing" ng:class="[\'A\', \'B\']"></div>')($rootScope);        $rootScope.$digest();        expect(element.hasClass('existing')).toBeTruthy();        expect(element.hasClass('A')).toBeTruthy(); @@ -227,7 +217,7 @@ describe("directive", function() {      it('should support adding multiple classes via a space delimited string', inject(function($rootScope, $compile) { -      var element = $compile('<div class="existing" ng:class="\'A B\'"></div>')($rootScope); +      element = $compile('<div class="existing" ng:class="\'A B\'"></div>')($rootScope);        $rootScope.$digest();        expect(element.hasClass('existing')).toBeTruthy();        expect(element.hasClass('A')).toBeTruthy(); @@ -236,7 +226,7 @@ describe("directive", function() {      it('should preserve class added post compilation with pre-existing classes', inject(function($rootScope, $compile) { -      var element = $compile('<div class="existing" ng:class="dynClass"></div>')($rootScope); +      element = $compile('<div class="existing" ng:class="dynClass"></div>')($rootScope);        $rootScope.dynClass = 'A';        $rootScope.$digest();        expect(element.hasClass('existing')).toBe(true); @@ -253,7 +243,7 @@ describe("directive", function() {      it('should preserve class added post compilation without pre-existing classes"', inject(function($rootScope, $compile) { -      var element = $compile('<div ng:class="dynClass"></div>')($rootScope); +      element = $compile('<div ng:class="dynClass"></div>')($rootScope);        $rootScope.dynClass = 'A';        $rootScope.$digest();        expect(element.hasClass('A')).toBe(true); @@ -269,119 +259,116 @@ describe("directive", function() {      it('should preserve other classes with similar name"', inject(function($rootScope, $compile) { -      var element = $compile('<div class="ui-panel ui-selected" ng:class="dynCls"></div>')($rootScope); +      element = $compile('<div class="ui-panel ui-selected" ng:class="dynCls"></div>')($rootScope);        $rootScope.dynCls = 'panel';        $rootScope.$digest();        $rootScope.dynCls = 'foo';        $rootScope.$digest(); -      expect(element[0].className).toBe('ui-panel ui-selected ng-directive foo'); +      expect(element[0].className).toBe('ui-panel ui-selected foo');      }));      it('should not add duplicate classes', inject(function($rootScope, $compile) { -      var element = $compile('<div class="panel bar" ng:class="dynCls"></div>')($rootScope); +      element = $compile('<div class="panel bar" ng:class="dynCls"></div>')($rootScope);        $rootScope.dynCls = 'panel';        $rootScope.$digest(); -      expect(element[0].className).toBe('panel bar ng-directive'); +      expect(element[0].className).toBe('panel bar');      }));      it('should remove classes even if it was specified via class attribute', inject(function($rootScope, $compile) { -      var element = $compile('<div class="panel bar" ng:class="dynCls"></div>')($rootScope); +      element = $compile('<div class="panel bar" ng:class="dynCls"></div>')($rootScope);        $rootScope.dynCls = 'panel';        $rootScope.$digest();        $rootScope.dynCls = 'window';        $rootScope.$digest(); -      expect(element[0].className).toBe('bar ng-directive window'); +      expect(element[0].className).toBe('bar window');      }));      it('should remove classes even if they were added by another code', inject(function($rootScope, $compile) { -      var element = $compile('<div ng:class="dynCls"></div>')($rootScope); +      element = $compile('<div ng:class="dynCls"></div>')($rootScope);        $rootScope.dynCls = 'foo';        $rootScope.$digest();        element.addClass('foo');        $rootScope.dynCls = '';        $rootScope.$digest(); -      expect(element[0].className).toBe('ng-directive');      }));      it('should convert undefined and null values to an empty string', inject(function($rootScope, $compile) { -      var element = $compile('<div ng:class="dynCls"></div>')($rootScope); +      element = $compile('<div ng:class="dynCls"></div>')($rootScope);        $rootScope.dynCls = [undefined, null];        $rootScope.$digest(); -      expect(element[0].className).toBe('ng-directive');      })); -  }); -  it('should ng:class odd/even', inject(function($rootScope, $compile) { -    var element = $compile('<ul><li ng:repeat="i in [0,1]" class="existing" ng:class-odd="\'odd\'" ng:class-even="\'even\'"></li><ul>')($rootScope); -    $rootScope.$digest(); -    var e1 = jqLite(element[0].childNodes[1]); -    var e2 = jqLite(element[0].childNodes[2]); -    expect(e1.hasClass('existing')).toBeTruthy(); -    expect(e1.hasClass('odd')).toBeTruthy(); -    expect(e2.hasClass('existing')).toBeTruthy(); -    expect(e2.hasClass('even')).toBeTruthy(); -  })); +    it('should ng:class odd/even', inject(function($rootScope, $compile) { +      element = $compile('<ul><li ng:repeat="i in [0,1]" class="existing" ng:class-odd="\'odd\'" ng:class-even="\'even\'"></li><ul>')($rootScope); +      $rootScope.$digest(); +      var e1 = jqLite(element[0].childNodes[1]); +      var e2 = jqLite(element[0].childNodes[2]); +      expect(e1.hasClass('existing')).toBeTruthy(); +      expect(e1.hasClass('odd')).toBeTruthy(); +      expect(e2.hasClass('existing')).toBeTruthy(); +      expect(e2.hasClass('even')).toBeTruthy(); +    })); -  it('should allow both ng:class and ng:class-odd/even on the same element', inject(function($rootScope, $compile) { -    var element = $compile('<ul>' + -      '<li ng:repeat="i in [0,1]" ng:class="\'plainClass\'" ' + -      'ng:class-odd="\'odd\'" ng:class-even="\'even\'"></li>' + -      '<ul>')($rootScope); -    $rootScope.$apply(); -    var e1 = jqLite(element[0].childNodes[1]); -    var e2 = jqLite(element[0].childNodes[2]); - -    expect(e1.hasClass('plainClass')).toBeTruthy(); -    expect(e1.hasClass('odd')).toBeTruthy(); -    expect(e1.hasClass('even')).toBeFalsy(); -    expect(e2.hasClass('plainClass')).toBeTruthy(); -    expect(e2.hasClass('even')).toBeTruthy(); -    expect(e2.hasClass('odd')).toBeFalsy(); -  })); +    it('should allow both ng:class and ng:class-odd/even on the same element', inject(function($rootScope, $compile) { +      element = $compile('<ul>' + +        '<li ng:repeat="i in [0,1]" ng:class="\'plainClass\'" ' + +        'ng:class-odd="\'odd\'" ng:class-even="\'even\'"></li>' + +        '<ul>')($rootScope); +      $rootScope.$apply(); +      var e1 = jqLite(element[0].childNodes[1]); +      var e2 = jqLite(element[0].childNodes[2]); +      expect(e1.hasClass('plainClass')).toBeTruthy(); +      expect(e1.hasClass('odd')).toBeTruthy(); +      expect(e1.hasClass('even')).toBeFalsy(); +      expect(e2.hasClass('plainClass')).toBeTruthy(); +      expect(e2.hasClass('even')).toBeTruthy(); +      expect(e2.hasClass('odd')).toBeFalsy(); +    })); -  it('should allow both ng:class and ng:class-odd/even with multiple classes', inject(function($rootScope, $compile) { -    var element = $compile('<ul>' + -      '<li ng:repeat="i in [0,1]" ng:class="[\'A\', \'B\']" ' + -      'ng:class-odd="[\'C\', \'D\']" ng:class-even="[\'E\', \'F\']"></li>' + -      '<ul>')($rootScope); -    $rootScope.$apply(); -    var e1 = jqLite(element[0].childNodes[1]); -    var e2 = jqLite(element[0].childNodes[2]); - -    expect(e1.hasClass('A')).toBeTruthy(); -    expect(e1.hasClass('B')).toBeTruthy(); -    expect(e1.hasClass('C')).toBeTruthy(); -    expect(e1.hasClass('D')).toBeTruthy(); -    expect(e1.hasClass('E')).toBeFalsy(); -    expect(e1.hasClass('F')).toBeFalsy(); - -    expect(e2.hasClass('A')).toBeTruthy(); -    expect(e2.hasClass('B')).toBeTruthy(); -    expect(e2.hasClass('E')).toBeTruthy(); -    expect(e2.hasClass('F')).toBeTruthy(); -    expect(e2.hasClass('C')).toBeFalsy(); -    expect(e2.hasClass('D')).toBeFalsy(); -  })); +    it('should allow both ng:class and ng:class-odd/even with multiple classes', inject(function($rootScope, $compile) { +      element = $compile('<ul>' + +        '<li ng:repeat="i in [0,1]" ng:class="[\'A\', \'B\']" ' + +        'ng:class-odd="[\'C\', \'D\']" ng:class-even="[\'E\', \'F\']"></li>' + +        '<ul>')($rootScope); +      $rootScope.$apply(); +      var e1 = jqLite(element[0].childNodes[1]); +      var e2 = jqLite(element[0].childNodes[2]); + +      expect(e1.hasClass('A')).toBeTruthy(); +      expect(e1.hasClass('B')).toBeTruthy(); +      expect(e1.hasClass('C')).toBeTruthy(); +      expect(e1.hasClass('D')).toBeTruthy(); +      expect(e1.hasClass('E')).toBeFalsy(); +      expect(e1.hasClass('F')).toBeFalsy(); + +      expect(e2.hasClass('A')).toBeTruthy(); +      expect(e2.hasClass('B')).toBeTruthy(); +      expect(e2.hasClass('E')).toBeTruthy(); +      expect(e2.hasClass('F')).toBeTruthy(); +      expect(e2.hasClass('C')).toBeFalsy(); +      expect(e2.hasClass('D')).toBeFalsy(); +    })); +  });    describe('ng:style', function() {      it('should set', inject(function($rootScope, $compile) { -      var element = $compile('<div ng:style="{height: \'40px\'}"></div>')($rootScope); +      element = $compile('<div ng:style="{height: \'40px\'}"></div>')($rootScope);        $rootScope.$digest();        expect(element.css('height')).toEqual('40px');      }));      it('should silently ignore undefined style', inject(function($rootScope, $compile) { -      var element = $compile('<div ng:style="myStyle"></div>')($rootScope); +      element = $compile('<div ng:style="myStyle"></div>')($rootScope);        $rootScope.$digest();        expect(element.hasClass('ng-exception')).toBeFalsy();      })); @@ -454,8 +441,8 @@ describe("directive", function() {    describe('ng:show', function() {      it('should show and hide an element', inject(function($rootScope, $compile) { -      var element = jqLite('<div ng:show="exp"></div>'); -      var element = $compile(element)($rootScope); +      element = jqLite('<div ng:show="exp"></div>'); +      element = $compile(element)($rootScope);        $rootScope.$digest();        expect(isCssVisible(element)).toEqual(false);        $rootScope.exp = true; @@ -465,8 +452,8 @@ describe("directive", function() {      it('should make hidden element visible', inject(function($rootScope, $compile) { -      var element = jqLite('<div style="display: none" ng:show="exp"></div>'); -      var element = $compile(element)($rootScope); +      element = jqLite('<div style="display: none" ng:show="exp"></div>'); +      element = $compile(element)($rootScope);        expect(isCssVisible(element)).toBe(false);        $rootScope.exp = true;        $rootScope.$digest(); @@ -476,8 +463,8 @@ describe("directive", function() {    describe('ng:hide', function() {      it('should hide an element', inject(function($rootScope, $compile) { -      var element = jqLite('<div ng:hide="exp"></div>'); -      var element = $compile(element)($rootScope); +      element = jqLite('<div ng:hide="exp"></div>'); +      element = $compile(element)($rootScope);        expect(isCssVisible(element)).toBe(true);        $rootScope.exp = true;        $rootScope.$digest(); @@ -552,7 +539,7 @@ describe("directive", function() {    describe('ng:cloak', function() {      it('should get removed when an element is compiled', inject(function($rootScope, $compile) { -      var element = jqLite('<div ng:cloak></div>'); +      element = jqLite('<div ng:cloak></div>');        expect(element.attr('ng:cloak')).toBe('');        $compile(element);        expect(element.attr('ng:cloak')).toBeUndefined(); @@ -560,7 +547,7 @@ describe("directive", function() {      it('should remove ng-cloak class from a compiled element', inject(function($rootScope, $compile) { -      var element = jqLite('<div ng:cloak class="foo ng-cloak bar"></div>'); +      element = jqLite('<div ng:cloak class="foo ng-cloak bar"></div>');        expect(element.hasClass('foo')).toBe(true);        expect(element.hasClass('ng-cloak')).toBe(true); diff --git a/test/markupSpec.js b/test/markupSpec.js index 0dcbbfe9..6f8e518e 100644 --- a/test/markupSpec.js +++ b/test/markupSpec.js @@ -1,33 +1,38 @@  'use strict';  describe("markups", function() { +  var element; + +  afterEach(function() { +    dealoc(element); +  });    it('should translate {{}} in text', inject(function($rootScope, $compile) { -    var element = $compile('<div>hello {{name}}!</div>')($rootScope) -    expect(sortedHtml(element)).toEqual('<div>hello <span ng:bind="name"></span>!</div>'); +    element = $compile('<div>hello {{name}}!</div>')($rootScope) +    $rootScope.$digest(); +    expect(sortedHtml(element)).toEqual('<div>hello !</div>');      $rootScope.name = 'Misko';      $rootScope.$digest(); -    expect(sortedHtml(element)).toEqual('<div>hello <span ng:bind="name">Misko</span>!</div>'); +    expect(sortedHtml(element)).toEqual('<div>hello Misko!</div>');    }));    it('should translate {{}} in terminal nodes', inject(function($rootScope, $compile) { -    var element = $compile('<select ng:model="x"><option value="">Greet {{name}}!</option></select>')($rootScope) +    element = $compile('<select ng:model="x"><option value="">Greet {{name}}!</option></select>')($rootScope)      $rootScope.$digest();      expect(sortedHtml(element).replace(' selected="true"', '')).        toEqual('<select ng:model="x">' + -                '<option ng:bind-template="Greet {{name}}!">Greet !</option>' + +                '<option>Greet !</option>' +                '</select>');      $rootScope.name = 'Misko';      $rootScope.$digest();      expect(sortedHtml(element).replace(' selected="true"', '')).        toEqual('<select ng:model="x">' + -                '<option ng:bind-template="Greet {{name}}!">Greet Misko!</option>' + +                '<option>Greet Misko!</option>' +                '</select>');    }));    it('should translate {{}} in attributes', inject(function($rootScope, $compile) { -    var element = $compile('<div src="http://server/{{path}}.png"/>')($rootScope) -    expect(element.attr('ng:bind-attr')).toEqual('{"src":"http://server/{{path}}.png"}'); +    element = $compile('<div src="http://server/{{path}}.png"/>')($rootScope)      $rootScope.path = 'a/b';      $rootScope.$digest();      expect(element.attr('src')).toEqual("http://server/a/b.png"); @@ -56,36 +61,38 @@ describe("markups", function() {      it('should populate value attribute on OPTION', inject(function($rootScope, $compile) { -      var element = $compile('<select ng:model="x"><option>abc</option></select>')($rootScope) +      element = $compile('<select ng:model="x"><option>abc</option></select>')($rootScope)        expect(element).toHaveValue('abc');      }));      it('should ignore value if already exists', inject(function($rootScope, $compile) { -      var element = $compile('<select ng:model="x"><option value="abc">xyz</option></select>')($rootScope) +      element = $compile('<select ng:model="x"><option value="abc">xyz</option></select>')($rootScope)        expect(element).toHaveValue('abc');      }));      it('should set value even if newlines present', inject(function($rootScope, $compile) { -      var element = $compile('<select ng:model="x"><option attr="\ntext\n" \n>\nabc\n</option></select>')($rootScope) +      element = $compile('<select ng:model="x"><option attr="\ntext\n" \n>\nabc\n</option></select>')($rootScope)        expect(element).toHaveValue('\nabc\n');      }));      it('should set value even if self closing HTML', inject(function($rootScope, $compile) {        // IE removes the \n from option, which makes this test pointless        if (msie) return; -      var element = $compile('<select ng:model="x"><option>\n</option></select>')($rootScope) +      element = $compile('<select ng:model="x"><option>\n</option></select>')($rootScope)        expect(element).toHaveValue('\n');      }));    });    it('should bind href', inject(function($rootScope, $compile) { -    var element = $compile('<a ng:href="{{url}}"></a>')($rootScope) -    expect(sortedHtml(element)).toEqual('<a ng:bind-attr="{"href":"{{url}}"}"></a>'); +    element = $compile('<a ng:href="{{url}}"></a>')($rootScope) +    $rootScope.url = 'http://server' +    $rootScope.$digest(); +    expect(element.attr('href')).toEqual('http://server');    }));    it('should bind disabled', inject(function($rootScope, $compile) { -    var element = $compile('<button ng:disabled="{{isDisabled}}">Button</button>')($rootScope) +    element = $compile('<button ng:disabled="{{isDisabled}}">Button</button>')($rootScope)      $rootScope.isDisabled = false;      $rootScope.$digest();      expect(element.attr('disabled')).toBeFalsy(); @@ -95,7 +102,7 @@ describe("markups", function() {    }));    it('should bind checked', inject(function($rootScope, $compile) { -    var element = $compile('<input type="checkbox" ng:checked="{{isChecked}}" />')($rootScope) +    element = $compile('<input type="checkbox" ng:checked="{{isChecked}}" />')($rootScope)      $rootScope.isChecked = false;      $rootScope.$digest();      expect(element.attr('checked')).toBeFalsy(); @@ -105,7 +112,7 @@ describe("markups", function() {    }));    it('should bind selected', inject(function($rootScope, $compile) { -    var element = $compile('<select><option value=""></option><option ng:selected="{{isSelected}}">Greetings!</option></select>')($rootScope) +    element = $compile('<select><option value=""></option><option ng:selected="{{isSelected}}">Greetings!</option></select>')($rootScope)      jqLite(document.body).append(element)      $rootScope.isSelected=false;      $rootScope.$digest(); @@ -116,7 +123,7 @@ describe("markups", function() {    }));    it('should bind readonly', inject(function($rootScope, $compile) { -    var element = $compile('<input type="text" ng:readonly="{{isReadonly}}" />')($rootScope) +    element = $compile('<input type="text" ng:readonly="{{isReadonly}}" />')($rootScope)      $rootScope.isReadonly=false;      $rootScope.$digest();      expect(element.attr('readOnly')).toBeFalsy(); @@ -126,7 +133,7 @@ describe("markups", function() {    }));    it('should bind multiple', inject(function($rootScope, $compile) { -    var element = $compile('<select ng:multiple="{{isMultiple}}"></select>')($rootScope) +    element = $compile('<select ng:multiple="{{isMultiple}}"></select>')($rootScope)      $rootScope.isMultiple=false;      $rootScope.$digest();      expect(element.attr('multiple')).toBeFalsy(); @@ -136,38 +143,37 @@ describe("markups", function() {    }));    it('should bind src', inject(function($rootScope, $compile) { -    var element = $compile('<div ng:src="{{url}}" />')($rootScope) +    element = $compile('<div ng:src="{{url}}" />')($rootScope)      $rootScope.url = 'http://localhost/';      $rootScope.$digest();      expect(element.attr('src')).toEqual('http://localhost/');    }));    it('should bind href and merge with other attrs', inject(function($rootScope, $compile) { -    var element = $compile('<a ng:href="{{url}}" rel="{{rel}}"></a>')($rootScope) -    expect(sortedHtml(element)).toEqual('<a ng:bind-attr="{"href":"{{url}}","rel":"{{rel}}"}"></a>'); +    element = $compile('<a ng:href="{{url}}" rel="{{rel}}"></a>')($rootScope); +    $rootScope.url = 'http://server'; +    $rootScope.rel = 'REL'; +    $rootScope.$digest(); +    expect(element.attr('href')).toEqual('http://server'); +    expect(element.attr('rel')).toEqual('REL');    })); -  it('should bind Text with no Bindings', inject(function($compile) { -    var $rootScope; -    function newScope (){ -      return $rootScope = angular.injector(['ng']).get('$rootScope'); -    } +  it('should bind Text with no Bindings', inject(function($compile, $rootScope) {      forEach(['checked', 'disabled', 'multiple', 'readonly', 'selected'], function(name) { -      var element = $compile('<div ng:' + name + '="some"></div>')(newScope()) -      expect(element.attr('ng:bind-attr')).toBe('{"' + name +'":"some"}'); +      element = $compile('<div ng:' + name + '="some"></div>')($rootScope)        $rootScope.$digest();        expect(element.attr(name)).toBe(name);        dealoc(element);      }); -    var element = $compile('<div ng:src="some"></div>')(newScope()) +    element = $compile('<div ng:src="some"></div>')($rootScope)      $rootScope.$digest(); -    expect(sortedHtml(element)).toEqual('<div ng:bind-attr="{"src":"some"}" src="some"></div>'); +    expect(element.attr('src')).toEqual('some');      dealoc(element); -    var element = $compile('<div ng:href="some"></div>')(newScope()) +    element = $compile('<div ng:href="some"></div>')($rootScope)      $rootScope.$digest(); -    expect(sortedHtml(element)).toEqual('<div href="some" ng:bind-attr="{"href":"some"}"></div>'); +    expect(element.attr('href')).toEqual('some');      dealoc(element);    }));  }); diff --git a/test/sanitizerSpec.js b/test/sanitizerSpec.js index 7467a833..a33d8992 100644 --- a/test/sanitizerSpec.js +++ b/test/sanitizerSpec.js @@ -2,9 +2,13 @@  describe('HTML', function() { -  function expectHTML(html) { -    return expect(new HTML(html).get()); -  } +  var expectHTML; + +  beforeEach(inject(function($sanitize) { +    expectHTML = function(html){ +      return expect($sanitize(html)); +    }; +  }));    describe('htmlParser', function() {      var handler, start, text; diff --git a/test/scenario/dslSpec.js b/test/scenario/dslSpec.js index 79d479bb..c757d8a4 100644 --- a/test/scenario/dslSpec.js +++ b/test/scenario/dslSpec.js @@ -1,8 +1,13 @@  'use strict';  describe("angular.scenario.dsl", function() { +  var element;    var $window, $root; -  var application, eventLog; +  var eventLog; + +  afterEach(function() { +    dealoc(element); +  });    beforeEach(inject(function($injector) {      eventLog = []; @@ -393,28 +398,26 @@ describe("angular.scenario.dsl", function() {      describe('Repeater', function() {        var chain; -      beforeEach(function() { -        doc.append( -          '<ul>' + -          '  <li><span ng:bind="name" class="ng-binding">misko</span>' + -          '    <span ng:bind="test && gender" class="ng-binding">male</span></li>' + -          '  <li><span ng:bind="name" class="ng-binding">felisa</span>' + -          '    <span ng:bind="gender | uppercase" class="ng-binding">female</span></li>' + -          '</ul>' -        ); +      beforeEach(inject(function($compile, $rootScope) { +        element = $compile( +          '<ul><li ng-repeat="i in items">{{i.name}}  {{i.gender}}</li></ul>')($rootScope); +        $rootScope.items = [{name:'misko', gender:'male'}, {name:'felisa', gender:'female'}]; +        $rootScope.$apply(); +        doc.append(element);          chain = $root.dsl.repeater('ul li'); -      }); +      }));        it('should get the row count', function() {          chain.count();          expect($root.futureResult).toEqual(2);        }); -      it('should return 0 if repeater doesnt match', function() { -        doc.find('ul').html(''); +      it('should return 0 if repeater doesnt match', inject(function($rootScope) { +        $rootScope.items = []; +        $rootScope.$apply();          chain.count();          expect($root.futureResult).toEqual(0); -      }); +      }));        it('should get a row of bindings', function() {          chain.row(1); @@ -422,7 +425,7 @@ describe("angular.scenario.dsl", function() {        });        it('should get a column of bindings', function() { -        chain.column('gender'); +        chain.column('i.gender');          expect($root.futureResult).toEqual(['male', 'female']);        }); @@ -437,45 +440,60 @@ describe("angular.scenario.dsl", function() {      });      describe('Binding', function() { -      it('should select binding by name', function() { -        doc.append('<span class="ng-binding" ng:bind="foo.bar">some value</span>'); +      var compile; + +      beforeEach(inject(function($compile, $rootScope) { +        compile = function(html, value) { +          element = $compile(html)($rootScope); +          doc.append(element); +          $rootScope.foo = {bar: value || 'some value'}; +          $rootScope.$apply(); +        }; +      })); + + +      it('should select binding in interpolation', function() { +        compile('<span>{{ foo.bar }}</span>');          $root.dsl.binding('foo.bar');          expect($root.futureResult).toEqual('some value');        }); -      it('should select binding by regexp', function() { -        doc.append('<span class="ng-binding" ng:bind="foo.bar">some value</span>'); -        $root.dsl.binding(/^foo\..+/); +      it('should select binding in multiple interpolations', function() { +        compile('<span>{{ foo.bar }}<hr/> {{ true }}</span>'); +        $root.dsl.binding('foo.bar');          expect($root.futureResult).toEqual('some value'); + +        $root.dsl.binding('true'); +        expect($root.futureResult).toEqual('true');        }); -      it('should return value for input elements', function() { -        doc.append('<input type="text" class="ng-binding" ng:bind="foo.bar" value="some value"/>'); +      it('should select binding by name', function() { +        compile('<span ng:bind=" foo.bar "></span>');          $root.dsl.binding('foo.bar');          expect($root.futureResult).toEqual('some value');        }); -      it('should return value for textarea elements', function() { -        doc.append('<textarea class="ng-binding" ng:bind="foo.bar">some value</textarea>'); -        $root.dsl.binding('foo.bar'); +      it('should select binding by regexp', function() { +        compile('<span ng:bind="foo.bar">some value</span>'); +        $root.dsl.binding(/^foo\..+/);          expect($root.futureResult).toEqual('some value');        });        it('should return innerHTML for all the other elements', function() { -        doc.append('<div class="ng-binding" ng:bind="foo.bar">some <b>value</b></div>'); +        compile('<div ng-bind-html="foo.bar"></div>', 'some <b>value</b>');          $root.dsl.binding('foo.bar');          expect($root.futureResult.toLowerCase()).toEqual('some <b>value</b>');        });        it('should select binding in template by name', function() { -        doc.append('<pre class="ng-binding" ng:bind-template="foo {{bar}} baz">foo some baz</pre>'); -        $root.dsl.binding('bar'); -        expect($root.futureResult).toEqual('foo some baz'); +        compile('<pre ng:bind-template="foo {{foo.bar}} baz"></pre>', 'bar'); +        $root.dsl.binding('foo.bar'); +        expect($root.futureResult).toEqual('bar');        });        it('should match bindings by substring match', function() { -        doc.append('<pre class="ng-binding" ng:bind="foo.bar() && test.baz() | filter">binding value</pre>'); -        $root.dsl.binding('test.baz'); +        compile('<pre ng:bind="foo.bar | filter"></pre>', 'binding value'); +        $root.dsl.binding('foo . bar');          expect($root.futureResult).toEqual('binding value');        }); @@ -485,7 +503,7 @@ describe("angular.scenario.dsl", function() {        });        it('should return error if no binding matches', function() { -        doc.append('<span class="ng-binding" ng:bind="foo">some value</span>'); +        compile('<span ng:bind="foo">some value</span>');          $root.dsl.binding('foo.bar');          expect($root.futureError).toMatch(/did not match/);        }); diff --git a/test/service/filter/filtersSpec.js b/test/service/filter/filtersSpec.js index cc006447..98651c58 100644 --- a/test/service/filter/filtersSpec.js +++ b/test/service/filter/filtersSpec.js @@ -153,14 +153,6 @@ describe('filters', function() {      });    }); -  describe('html', function() { -    it('should do basic filter', function() { -      var html = filter('html')("a<b>c</b>d"); -      expect(html instanceof HTML).toBeTruthy(); -      expect(html.html).toEqual("a<b>c</b>d"); -    }); -  }); -    describe('linky', function() {      var linky; @@ -169,7 +161,7 @@ describe('filters', function() {      }));      it('should do basic filter', function() { -      expect(linky("http://ab/ (http://a/) <http://a/> http://1.2/v:~-123. c").html). +      expect(linky("http://ab/ (http://a/) <http://a/> http://1.2/v:~-123. c")).          toEqual('<a href="http://ab/">http://ab/</a> ' +                  '(<a href="http://a/">http://a/</a>) ' +                  '<<a href="http://a/">http://a/</a>> ' + @@ -178,11 +170,11 @@ describe('filters', function() {      });      it('should handle mailto:', function() { -      expect(linky("mailto:me@example.com").html). +      expect(linky("mailto:me@example.com")).                        toEqual('<a href="mailto:me@example.com">me@example.com</a>'); -      expect(linky("me@example.com").html). +      expect(linky("me@example.com")).                        toEqual('<a href="mailto:me@example.com">me@example.com</a>'); -      expect(linky("send email to me@example.com, but").html). +      expect(linky("send email to me@example.com, but")).          toEqual('send email to <a href="mailto:me@example.com">me@example.com</a>, but');      });    }); diff --git a/test/service/logSpec.js b/test/service/logSpec.js index 98158ae0..df2bc933 100644 --- a/test/service/logSpec.js +++ b/test/service/logSpec.js @@ -69,7 +69,7 @@ describe('$log', function() {        e.stack = undefined;        $log = new $LogProvider().$get[1]({console:{error:function() { -        errorArgs = arguments; +        errorArgs = [].slice.call(arguments, 0);        }}});      }); diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index 85c844cb..1b4f11ba 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -61,9 +61,19 @@ afterEach(function() {  function dealoc(obj) {    if (obj) { -    var element = obj.$element || obj || {}; -    if (element.nodeName) element = jqLite(element); -    if (element.dealoc) element.dealoc(); +    if (isElement(obj)) { +      var element = obj; +      if (element.nodeName) element = jqLite(element); +      if (element.dealoc) element.dealoc(); +    } else { +      for(var key in jqCache) { +        var value = jqCache[key]; +        if (value.$scope == obj) { +          delete jqCache[key]; +        } +      } +    } +    }  } diff --git a/test/widget/inputSpec.js b/test/widget/inputSpec.js index 3e073d95..3b3aa282 100644 --- a/test/widget/inputSpec.js +++ b/test/widget/inputSpec.js @@ -51,7 +51,6 @@ describe('widget: input', function() {      it('should bind update scope from model', function() {        createInput(); -      expect(scope.form.name.$required).toBe(false);        scope.name = 'misko';        scope.$digest();        expect(inputElement.val()).toEqual('misko'); @@ -60,7 +59,6 @@ describe('widget: input', function() {      it('should require', function() {        createInput({required:''}); -      expect(scope.form.name.$required).toBe(true);        scope.$digest();        expect(scope.form.name.$valid).toBe(false);        scope.name = 'misko'; @@ -159,7 +157,7 @@ describe('widget: input', function() {                  '</div>');          scope.obj = { abc: { name: 'Misko'} };          scope.$digest(); -        expect(scope.$element.find('input').val()).toEqual('Misko'); +        expect(element.find('input').val()).toEqual('Misko');        }); @@ -181,7 +179,7 @@ describe('widget: input', function() {          it("should render as blank if null", function() {            compile('<input type="text" ng:model="age" ng:format="number" ng:init="age=null"/>');            expect(scope.age).toBeNull(); -          expect(scope.$element[0].value).toEqual(''); +          expect(element[0].value).toEqual('');          }); @@ -189,19 +187,19 @@ describe('widget: input', function() {            compile('<input type="number" ng:model="age"/>');            scope.age = 123;            scope.$digest(); -          expect(scope.$element.val()).toEqual('123'); +          expect(element.val()).toEqual('123');            try {              // to allow non-number values, we have to change type so that              // the browser which have number validation will not interfere with              // this test. IE8 won't allow it hence the catch. -            scope.$element[0].setAttribute('type', 'text'); +            element[0].setAttribute('type', 'text');            } catch (e){} -          scope.$element.val('123X'); -          browserTrigger(scope.$element, 'change'); +          element.val('123X'); +          browserTrigger(element, 'change');            defer.flush(); -          expect(scope.$element.val()).toEqual('123X'); +          expect(element.val()).toEqual('123X');            expect(scope.age).toEqual(123); -          expect(scope.$element).toBeInvalid(); +          expect(element).toBeInvalid();          }); @@ -211,28 +209,28 @@ describe('widget: input', function() {            // the user from ever typying ','.            compile('<input type="list" ng:model="list"/>'); -          scope.$element.val('a '); -          browserTrigger(scope.$element, 'change'); +          element.val('a '); +          browserTrigger(element, 'change');            defer.flush(); -          expect(scope.$element.val()).toEqual('a '); +          expect(element.val()).toEqual('a ');            expect(scope.list).toEqual(['a']); -          scope.$element.val('a ,'); -          browserTrigger(scope.$element, 'change'); +          element.val('a ,'); +          browserTrigger(element, 'change');            defer.flush(); -          expect(scope.$element.val()).toEqual('a ,'); +          expect(element.val()).toEqual('a ,');            expect(scope.list).toEqual(['a']); -          scope.$element.val('a , '); -          browserTrigger(scope.$element, 'change'); +          element.val('a , '); +          browserTrigger(element, 'change');            defer.flush(); -          expect(scope.$element.val()).toEqual('a , '); +          expect(element.val()).toEqual('a , ');            expect(scope.list).toEqual(['a']); -          scope.$element.val('a , b'); -          browserTrigger(scope.$element, 'change'); +          element.val('a , b'); +          browserTrigger(element, 'change');            defer.flush(); -          expect(scope.$element.val()).toEqual('a , b'); +          expect(element.val()).toEqual('a , b');            expect(scope.list).toEqual(['a', 'b']);          }); @@ -240,7 +238,7 @@ describe('widget: input', function() {          it("should come up blank when no value specified", function() {            compile('<input type="number" ng:model="age"/>');            scope.$digest(); -          expect(scope.$element.val()).toEqual(''); +          expect(element.val()).toEqual('');            expect(scope.age).toEqual(null);          });        }); @@ -250,7 +248,7 @@ describe('widget: input', function() {          it("should format booleans", function() {            compile('<input type="checkbox" ng:model="name" ng:init="name=false"/>');            expect(scope.name).toBe(false); -          expect(scope.$element[0].checked).toBe(false); +          expect(element[0].checked).toBe(false);          }); @@ -270,15 +268,15 @@ describe('widget: input', function() {            scope.name='y';            scope.$digest(); -          expect(scope.$element[0].checked).toBe(true); +          expect(element[0].checked).toBe(true);            scope.name='n';            scope.$digest(); -          expect(scope.$element[0].checked).toBe(false); +          expect(element[0].checked).toBe(false);            scope.name='abc';            scope.$digest(); -          expect(scope.$element[0].checked).toBe(false); +          expect(element[0].checked).toBe(false);            browserTrigger(element);            expect(scope.name).toEqual('y'); @@ -302,7 +300,6 @@ describe('widget: input', function() {      it("should process required", inject(function($formFactory) {        compile('<input type="text" ng:model="price" name="p" required/>', jqLite(document.body)); -      expect($formFactory.rootForm.p.$required).toBe(true);        expect(element.hasClass('ng-invalid')).toBeTruthy();        scope.price = 'xxx'; @@ -394,7 +391,7 @@ describe('widget: input', function() {          '</div>');          expect(scope.choose).toEqual('C'); -        var inputs = scope.$element.find('input'); +        var inputs = element.find('input');          expect(inputs[1].checked).toBe(false);          expect(inputs[2].checked).toBe(true);        }); @@ -408,7 +405,7 @@ describe('widget: input', function() {          '</div>');          expect(scope.choose).toEqual('A'); -        var inputs = scope.$element.find('input'); +        var inputs = element.find('input');          expect(inputs[0].checked).toBe(true);          expect(inputs[1].checked).toBe(false);        }); @@ -421,7 +418,7 @@ describe('widget: input', function() {                '       type="radio" ng:model="choice" value="{{item}}" name="choice">'+              '</li>'); -        var inputs = scope.$element.find('input'); +        var inputs = element.find('input');          expect(inputs[0].checked).toBe(false);          expect(inputs[1].checked).toBe(false); @@ -435,7 +432,7 @@ describe('widget: input', function() {            function($rootScope, $compile){          $rootScope.choice = 'b';          $rootScope.items = ['a', 'b']; -        var element = $compile( +        element = $compile(              '<li>'+                '<input ng:repeat="item in items" ' +                '       type="radio" ng:model="choice" value="{{item}}" name="choice">'+ @@ -465,21 +462,22 @@ describe('widget: input', function() {          $rootScope.value = undefined;          $rootScope.$digest();          expect(element.val()).toEqual(''); +        dealoc(element);        }));      });      it('should ignore text widget which have no name', function() {        compile('<input type="text"/>'); -      expect(scope.$element.attr('ng-exception')).toBeFalsy(); -      expect(scope.$element.hasClass('ng-exception')).toBeFalsy(); +      expect(element.attr('ng-exception')).toBeFalsy(); +      expect(element.hasClass('ng-exception')).toBeFalsy();      });      it('should ignore checkbox widget which have no name', function() {        compile('<input type="checkbox"/>'); -      expect(scope.$element.attr('ng-exception')).toBeFalsy(); -      expect(scope.$element.hasClass('ng-exception')).toBeFalsy(); +      expect(element.attr('ng-exception')).toBeFalsy(); +      expect(element.hasClass('ng-exception')).toBeFalsy();      }); @@ -506,6 +504,7 @@ describe('widget: input', function() {        expect(formFactory).toBe($formFactory);        expect(input[0]).toBe(element[0]); +      dealoc(element);      }));      it('should throw an error of Controller not declared in scope', inject(function($rootScope, $compile) { @@ -530,13 +529,13 @@ describe('widget: input', function() {          forEach(validList, function(value){            it('should validate "' + value + '"', function() {              setup(value); -            expect(scope.$element).toBeValid(); +            expect(element).toBeValid();            });          });          forEach(invalidList, function(value){            it('should NOT validate "' + value + '"', function() {              setup(value); -            expect(scope.$element).toBeInvalid(); +            expect(element).toBeInvalid();            });          }); @@ -553,10 +552,10 @@ describe('widget: input', function() {              // to allow non-number values, we have to change type so that              // the browser which have number validation will not interfere with              // this test. IE8 won't allow it hence the catch. -            scope.$element[0].setAttribute('type', 'text'); +            element[0].setAttribute('type', 'text');            } catch (e){}            if (value != undefined) { -            scope.$element.val(value); +            element.val(value);              browserTrigger(element, 'keydown');              defer.flush();            } diff --git a/test/widget/selectSpec.js b/test/widget/selectSpec.js index 5d92e674..7206ade8 100644 --- a/test/widget/selectSpec.js +++ b/test/widget/selectSpec.js @@ -13,7 +13,7 @@ describe('select', function() {        } else {          element = jqLite(html);        } -      $compile(element)($rootScope); +      element = $compile(element)($rootScope);        scope.$apply();        return scope;      }; @@ -37,7 +37,7 @@ describe('select', function() {        scope.b = 'bar';        scope.$digest(); -      expect(scope.$element.text()).toBe('foobarC'); +      expect(element.text()).toBe('foobarC');      });      it('should require', inject(function($formFactory) { diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index 88d9e1b8..6e115a36 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -1,9 +1,15 @@  'use strict';  describe('widget', function() { -  describe('ng:switch', function() { +  var element; + +  afterEach(function(){ +    dealoc(element); +  }); + +  describe('ng:switch', inject(function($rootScope, $compile) {      it('should switch on value change', inject(function($rootScope, $compile) { -      var element = $compile( +      element = $compile(          '<ng:switch on="select">' +            '<div ng:switch-when="1">first:{{name}}</div>' +            '<div ng:switch-when="2">second:{{name}}</div>' + @@ -29,7 +35,7 @@ describe('widget', function() {      it('should switch on switch-when-default', inject(function($rootScope, $compile) { -      var element = $compile( +      element = $compile(          '<ng:switch on="select">' +            '<div ng:switch-when="1">one</div>' +            '<div ng:switch-default>other</div>' + @@ -43,7 +49,7 @@ describe('widget', function() {      it('should call change on switch', inject(function($rootScope, $compile) { -      var element = $compile( +      element = $compile(          '<ng:switch on="url" change="name=\'works\'">' +            '<div ng:switch-when="a">{{name}}</div>' +          '</ng:switch>')($rootScope); @@ -52,7 +58,7 @@ describe('widget', function() {        expect($rootScope.name).toEqual(undefined);        expect(element.text()).toEqual('works');      })); -  }); +  }));    describe('ng:include', function() { @@ -66,7 +72,7 @@ describe('widget', function() {      it('should include on external file', inject(putIntoCache('myUrl', '{{name}}'),          function($rootScope, $compile, $browser) { -      var element = jqLite('<ng:include src="url" scope="childScope"></ng:include>'); +      element = jqLite('<ng:include src="url" scope="childScope"></ng:include>');        element = $compile(element)($rootScope);        $rootScope.childScope = $rootScope.$new();        $rootScope.childScope.name = 'misko'; @@ -79,7 +85,7 @@ describe('widget', function() {      it('should remove previously included text if a falsy value is bound to src', inject(            putIntoCache('myUrl', '{{name}}'),            function($rootScope, $compile, $browser) { -      var element = jqLite('<ng:include src="url" scope="childScope"></ng:include>'); +      element = jqLite('<ng:include src="url" scope="childScope"></ng:include>');        element = $compile(element)($rootScope);        $rootScope.childScope = $rootScope.$new();        $rootScope.childScope.name = 'igor'; @@ -97,7 +103,7 @@ describe('widget', function() {      it('should allow this for scope', inject(putIntoCache('myUrl', '{{"abc"}}'),            function($rootScope, $compile, $browser) { -      var element = jqLite('<ng:include src="url" scope="this"></ng:include>'); +      element = jqLite('<ng:include src="url" scope="this"></ng:include>');        element = $compile(element)($rootScope);        $rootScope.url = 'myUrl';        $rootScope.$digest(); @@ -115,7 +121,7 @@ describe('widget', function() {      it('should evaluate onload expression when a partial is loaded', inject(          putIntoCache('myUrl', 'my partial'),          function($rootScope, $compile, $browser) { -      var element = jqLite('<ng:include src="url" onload="loaded = true"></ng:include>'); +      element = jqLite('<ng:include src="url" onload="loaded = true"></ng:include>');        element = $compile(element)($rootScope);        expect($rootScope.loaded).not.toBeDefined(); @@ -130,7 +136,7 @@ describe('widget', function() {      it('should destroy old scope', inject(putIntoCache('myUrl', 'my partial'),            function($rootScope, $compile, $browser) { -      var element = jqLite('<ng:include src="url"></ng:include>'); +      element = jqLite('<ng:include src="url"></ng:include>');        element = $compile(element)($rootScope);        expect($rootScope.$$childHead).toBeFalsy(); @@ -147,7 +153,7 @@ describe('widget', function() {      it('should do xhr request and cache it',          inject(function($rootScope, $httpBackend, $compile, $browser) { -      var element = $compile('<ng:include src="url"></ng:include>')($rootScope); +      element = $compile('<ng:include src="url"></ng:include>')($rootScope);        $httpBackend.expect('GET', 'myUrl').respond('my partial');        $rootScope.url = 'myUrl'; @@ -168,7 +174,7 @@ describe('widget', function() {      it('should clear content when error during xhr request',          inject(function($httpBackend, $compile, $rootScope) { -      var element = $compile('<ng:include src="url">content</ng:include>')($rootScope); +      element = $compile('<ng:include src="url">content</ng:include>')($rootScope);        $httpBackend.expect('GET', 'myUrl').respond(404, '');        $rootScope.url = 'myUrl'; @@ -182,7 +188,7 @@ describe('widget', function() {      it('should be async even if served from cache', inject(            putIntoCache('myUrl', 'my partial'),            function($rootScope, $compile, $browser) { -      var element = $compile('<ng:include src="url"></ng:include>')($rootScope); +      element = $compile('<ng:include src="url"></ng:include>')($rootScope);        $rootScope.url = 'myUrl'; @@ -199,8 +205,8 @@ describe('widget', function() {      it('should discard pending xhr callbacks if a new template is requested before the current ' +          'finished loading', inject(function($rootScope, $compile, $httpBackend) { -      var element = jqLite("<ng:include src='templateUrl'></ng:include>"), -          log = []; +      element = jqLite("<ng:include src='templateUrl'></ng:include>"); +      var log = [];        $rootScope.templateUrl = 'myUrl1';        $rootScope.logger = function(msg) { @@ -234,7 +240,7 @@ describe('widget', function() {        function compileAndLink(tpl) {          return function($compile, $rootScope) { -          $compile(tpl)($rootScope); +          element = $compile(tpl)($rootScope);          };        } @@ -294,7 +300,7 @@ describe('widget', function() {            preventDefaultCalled = false,            event; -      var element = $compile('<a href="">empty link</a>')($rootScope); +      element = $compile('<a href="">empty link</a>')($rootScope);        if (msie < 9) { @@ -327,7 +333,7 @@ describe('widget', function() {    describe('@ng:repeat', function() {      it('should ng:repeat over array', inject(function($rootScope, $compile) { -      var element = $compile( +      element = $compile(          '<ul>' +            '<li ng:repeat="item in items" ng:init="suffix = \';\'" ng:bind="item + suffix"></li>' +          '</ul>')($rootScope); @@ -355,7 +361,7 @@ describe('widget', function() {      it('should ng:repeat over object', inject(function($rootScope, $compile) { -      var element = $compile( +      element = $compile(          '<ul>' +            '<li ng:repeat="(key, value) in items" ng:bind="key + \':\' + value + \';\' "></li>' +          '</ul>')($rootScope); @@ -370,7 +376,7 @@ describe('widget', function() {        Class.prototype.abc = function() {};        Class.prototype.value = 'abc'; -      var element = $compile( +      element = $compile(          '<ul>' +            '<li ng:repeat="(key, value) in items" ng:bind="key + \':\' + value + \';\' "></li>' +          '</ul>')($rootScope); @@ -383,7 +389,7 @@ describe('widget', function() {      it('should error on wrong parsing of ng:repeat', inject(function($rootScope, $compile, $log) {        expect(function() { -        var element = $compile('<ul><li ng:repeat="i dont parse"></li></ul>')($rootScope); +        element = $compile('<ul><li ng:repeat="i dont parse"></li></ul>')($rootScope);        }).toThrow("Expected ng:repeat in form of '_item_ in _collection_' but got 'i dont parse'.");        $log.error.logs.shift(); @@ -392,7 +398,7 @@ describe('widget', function() {      it('should expose iterator offset as $index when iterating over arrays',          inject(function($rootScope, $compile) { -      var element = $compile( +      element = $compile(          '<ul>' +            '<li ng:repeat="item in items" ng:bind="item + $index + \'|\'"></li>' +          '</ul>')($rootScope); @@ -404,7 +410,7 @@ describe('widget', function() {      it('should expose iterator offset as $index when iterating over objects',          inject(function($rootScope, $compile) { -      var element = $compile( +      element = $compile(          '<ul>' +            '<li ng:repeat="(key, val) in items" ng:bind="key + \':\' + val + $index + \'|\'"></li>' +          '</ul>')($rootScope); @@ -416,7 +422,7 @@ describe('widget', function() {      it('should expose iterator position as $position when iterating over arrays',          inject(function($rootScope, $compile) { -      var element = $compile( +      element = $compile(          '<ul>' +            '<li ng:repeat="item in items" ng:bind="item + \':\' + $position + \'|\'"></li>' +          '</ul>')($rootScope); @@ -437,7 +443,7 @@ describe('widget', function() {      it('should expose iterator position as $position when iterating over objects',          inject(function($rootScope, $compile) { -      var element = $compile( +      element = $compile(          '<ul>' +            '<li ng:repeat="(key, val) in items" ng:bind="key + \':\' + val + \':\' + $position + \'|\'">' +            '</li>' + @@ -454,7 +460,7 @@ describe('widget', function() {      it('should ignore $ and $$ properties', inject(function($rootScope, $compile) { -      var element = $compile('<ul><li ng:repeat="i in items">{{i}}|</li></ul>')($rootScope); +      element = $compile('<ul><li ng:repeat="i in items">{{i}}|</li></ul>')($rootScope);        $rootScope.items = ['a', 'b', 'c'];        $rootScope.items.$$hashkey = 'xxx';        $rootScope.items.$root = 'yyy'; @@ -465,7 +471,7 @@ describe('widget', function() {      it('should repeat over nested arrays', inject(function($rootScope, $compile) { -      var element = $compile( +      element = $compile(          '<ul>' +            '<li ng:repeat="subgroup in groups">' +              '<div ng:repeat="group in subgroup">{{group}}|</div>X' + @@ -480,7 +486,7 @@ describe('widget', function() {      it('should ignore non-array element properties when iterating over an array',          inject(function($rootScope, $compile) { -      var element = $compile('<ul><li ng:repeat="item in array">{{item}}|</li></ul>')($rootScope); +      element = $compile('<ul><li ng:repeat="item in array">{{item}}|</li></ul>')($rootScope);        $rootScope.array = ['a', 'b', 'c'];        $rootScope.array.foo = '23';        $rootScope.array.bar = function() {}; @@ -492,7 +498,7 @@ describe('widget', function() {      it('should iterate over non-existent elements of a sparse array',          inject(function($rootScope, $compile) { -      var element = $compile('<ul><li ng:repeat="item in array">{{item}}|</li></ul>')($rootScope); +      element = $compile('<ul><li ng:repeat="item in array">{{item}}|</li></ul>')($rootScope);        $rootScope.array = ['a', 'b'];        $rootScope.array[4] = 'c';        $rootScope.array[6] = 'd'; @@ -503,7 +509,7 @@ describe('widget', function() {      it('should iterate over all kinds of types', inject(function($rootScope, $compile) { -      var element = $compile('<ul><li ng:repeat="item in array">{{item}}|</li></ul>')($rootScope); +      element = $compile('<ul><li ng:repeat="item in array">{{item}}|</li></ul>')($rootScope);        $rootScope.array = ['a', 1, null, undefined, {}];        $rootScope.$digest(); @@ -512,7 +518,7 @@ describe('widget', function() {      describe('stability', function() { -      var a, b, c, d, lis, element; +      var a, b, c, d, lis;        beforeEach(inject(function($rootScope, $compile) {          element = $compile( @@ -602,7 +608,7 @@ describe('widget', function() {    describe('@ng:non-bindable', function() {      it('should prevent compilation of the owning element and its children',          inject(function($rootScope, $compile) { -      var element = $compile('<div ng:non-bindable><span ng:bind="name"></span></div>')($rootScope); +      element = $compile('<div ng:non-bindable><span ng:bind="name"></span></div>')($rootScope);        $rootScope.name =  'misko';        $rootScope.$digest();        expect(element.text()).toEqual(''); @@ -611,7 +617,6 @@ describe('widget', function() {    describe('ng:view', function() { -    var element;      beforeEach(inject(function($rootScope, $compile) {        element = $compile('<ng:view></ng:view>')($rootScope);      })); @@ -658,7 +663,7 @@ describe('widget', function() {        $location.path('/unknown');        $rootScope.$digest(); -      expect($rootScope.$element.text()).toEqual(''); +      expect(element.text()).toEqual('');      })); @@ -675,12 +680,13 @@ describe('widget', function() {        $rootScope.parentVar = 'new parent';        $rootScope.$digest(); -      expect($rootScope.$element.text()).toEqual('new parent'); +      expect(element.text()).toEqual('new parent');      }));      it('should be possible to nest ng:view in ng:include', inject(function() {        // TODO(vojta): refactor this test +      dealoc(element);        var injector = angular.injector(['ng', 'ngMock']);        var myApp = injector.get('$rootScope');        var $httpBackend = injector.get('$httpBackend'); @@ -690,7 +696,7 @@ describe('widget', function() {        var $route = injector.get('$route');        $route.when('/foo', {controller: angular.noop, template: 'viewPartial.html'}); -      var element = injector.get('$compile')( +      element = injector.get('$compile')(            '<div>' +              'include: <ng:include src="\'includePartial.html\'"> </ng:include>' +            '</div>')(myApp); @@ -699,15 +705,16 @@ describe('widget', function() {        $httpBackend.expect('GET', 'viewPartial.html').respond('content');        $httpBackend.flush(); -      expect(myApp.$element.text()).toEqual('include: view: content'); +      expect(element.text()).toEqual('include: view: content');        expect($route.current.template).toEqual('viewPartial.html');        dealoc(myApp); +      dealoc(element);      }));      it('should initialize view template after the view controller was initialized even when ' +         'templates were cached', -       inject(function($rootScope, $compile, $location, $httpBackend, $route, $browser) { +       inject(function($rootScope, $compile, $location, $httpBackend, $route) {        //this is a test for a regression that was introduced by making the ng:view cache sync        $route.when('/foo', {controller: ParentCtrl, template: 'viewPartial.html'}); @@ -750,7 +757,7 @@ describe('widget', function() {        $route.when('/foo', {template: 'myUrl1'});        $route.when('/bar', {template: 'myUrl2'}); -      expect($rootScope.$element.text()).toEqual(''); +      expect(element.text()).toEqual('');        $location.path('/foo');        $httpBackend.expect('GET', 'myUrl1').respond('<div>{{1+3}}</div>'); @@ -760,7 +767,7 @@ describe('widget', function() {        $rootScope.$digest();        $httpBackend.flush(); // now that we have two requests pending, flush! -      expect($rootScope.$element.text()).toEqual('2'); +      expect(element.text()).toEqual('2');      })); @@ -770,12 +777,12 @@ describe('widget', function() {        $location.path('/foo');        $httpBackend.expect('GET', 'myUrl1').respond(404, ''); -      $rootScope.$element.text('content'); +      element.text('content');        $rootScope.$digest();        $httpBackend.flush(); -      expect($rootScope.$element.text()).toBe(''); +      expect(element.text()).toBe('');      })); @@ -800,7 +807,6 @@ describe('widget', function() {    describe('ng:pluralize', function() {      describe('deal with pluralized strings without offset', function() { -       var element;         beforeEach(inject(function($rootScope, $compile) {            element = $compile(              '<ng:pluralize count="email"' + @@ -892,7 +898,7 @@ describe('widget', function() {      describe('deal with pluralized strings with offset', function() {        it('should show single/plural strings with offset', inject(function($rootScope, $compile) { -        var element = $compile( +        element = $compile(            "<ng:pluralize count=\"viewCount\"  offset=2 " +                "when=\"{'0': 'Nobody is viewing.'," +                        "'1': '{{p1}} is viewing.'," + | 
