From 9ee2cdff44e7d496774b340de816344126c457b3 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Tue, 22 Nov 2011 21:28:39 -0800 Subject: refactor(directives): connect new compiler - turn everything into a directive --- test/widgetsSpec.js | 94 ++++++++++++++++++++++++++++------------------------- 1 file changed, 50 insertions(+), 44 deletions(-) (limited to 'test/widgetsSpec.js') 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( '' + '
first:{{name}}
' + '
second:{{name}}
' + @@ -29,7 +35,7 @@ describe('widget', function() { it('should switch on switch-when-default', inject(function($rootScope, $compile) { - var element = $compile( + element = $compile( '' + '
one
' + '
other
' + @@ -43,7 +49,7 @@ describe('widget', function() { it('should call change on switch', inject(function($rootScope, $compile) { - var element = $compile( + element = $compile( '' + '
{{name}}
' + '
')($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(''); + element = jqLite(''); 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(''); + element = jqLite(''); 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(''); + element = jqLite(''); 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(''); + element = jqLite(''); 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(''); + element = jqLite(''); 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('')($rootScope); + element = $compile('')($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('content')($rootScope); + element = $compile('content')($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('')($rootScope); + element = $compile('')($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(""), - log = []; + element = jqLite(""); + 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('empty link')($rootScope); + element = $compile('empty link')($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( '')($rootScope); @@ -355,7 +361,7 @@ describe('widget', function() { it('should ng:repeat over object', inject(function($rootScope, $compile) { - var element = $compile( + element = $compile( '')($rootScope); @@ -370,7 +376,7 @@ describe('widget', function() { Class.prototype.abc = function() {}; Class.prototype.value = 'abc'; - var element = $compile( + element = $compile( '')($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('')($rootScope); + element = $compile('')($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( '')($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( '')($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( '')($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( '