aboutsummaryrefslogtreecommitdiffstats
path: root/test/ng/directive/ngIncludeSpec.js
diff options
context:
space:
mode:
authorVojta Jina2012-03-30 13:40:19 -0700
committerVojta Jina2012-04-03 10:10:44 -0700
commit5f70d615a5f7e102424c6adc15d7a6f697870b6e (patch)
tree791ce11e20caaf40dc9297fbc8863d604de2fd4d /test/ng/directive/ngIncludeSpec.js
parent06d0955074f79de553cc34fbf945045dc458e064 (diff)
downloadangular.js-5f70d615a5f7e102424c6adc15d7a6f697870b6e.tar.bz2
refactor(ngInclude): remove scope attribute
The purpose of allowing the scope to be specified was to enable the $route service to work together with ngInclude. However the functionality of creating scopes was in the recent past moved from the $route service to the ngView directive, so currently there is no valid use case for specifying the scope for ngInclude. In fact, allowing the scope to be defined can under certain circumstances lead to memory leaks. Breaks ngInclude does not have scope attribute anymore.
Diffstat (limited to 'test/ng/directive/ngIncludeSpec.js')
-rw-r--r--test/ng/directive/ngIncludeSpec.js56
1 files changed, 25 insertions, 31 deletions
diff --git a/test/ng/directive/ngIncludeSpec.js b/test/ng/directive/ngIncludeSpec.js
index ab63dd02..ae9454d6 100644
--- a/test/ng/directive/ngIncludeSpec.js
+++ b/test/ng/directive/ngIncludeSpec.js
@@ -18,11 +18,10 @@ describe('ng-include', function() {
it('should include on external file', inject(putIntoCache('myUrl', '{{name}}'),
function($rootScope, $compile) {
- element = jqLite('<ng:include src="url" scope="childScope"></ng:include>');
+ element = jqLite('<ng:include src="url"></ng:include>');
jqLite(document.body).append(element);
element = $compile(element)($rootScope);
- $rootScope.childScope = $rootScope.$new();
- $rootScope.childScope.name = 'misko';
+ $rootScope.name = 'misko';
$rootScope.url = 'myUrl';
$rootScope.$digest();
expect(element.text()).toEqual('misko');
@@ -46,10 +45,9 @@ describe('ng-include', function() {
it('should remove previously included text if a falsy value is bound to src', inject(
putIntoCache('myUrl', '{{name}}'),
function($rootScope, $compile) {
- element = jqLite('<ng:include src="url" scope="childScope"></ng:include>');
+ element = jqLite('<ng:include src="url"></ng:include>');
element = $compile(element)($rootScope);
- $rootScope.childScope = $rootScope.$new();
- $rootScope.childScope.name = 'igor';
+ $rootScope.name = 'igor';
$rootScope.url = 'myUrl';
$rootScope.$digest();
@@ -62,23 +60,6 @@ describe('ng-include', function() {
}));
- it('should allow this for scope', inject(putIntoCache('myUrl', '{{"abc"}}'),
- function($rootScope, $compile) {
- element = jqLite('<ng:include src="url" scope="this"></ng:include>');
- element = $compile(element)($rootScope);
- $rootScope.url = 'myUrl';
- $rootScope.$digest();
-
- // TODO(misko): because we are using scope==this, the eval gets registered
- // during the flush phase and hence does not get called.
- // I don't think passing 'this' makes sense. Does having scope on ng-include makes sense?
- // should we make scope="this" illegal?
- $rootScope.$digest();
-
- expect(element.text()).toEqual('abc');
- }));
-
-
it('should fire $includeContentLoaded event after linking the content', inject(
function($rootScope, $compile, $templateCache) {
var contentLoadedSpy = jasmine.createSpy('content loaded').andCallFake(function() {
@@ -111,20 +92,33 @@ describe('ng-include', function() {
}));
- it('should destroy old scope', inject(putIntoCache('myUrl', 'my partial'),
- function($rootScope, $compile) {
- element = jqLite('<ng:include src="url"></ng:include>');
- element = $compile(element)($rootScope);
+ it('should create child scope and destroy old one', inject(
+ function($rootScope, $compile, $httpBackend) {
+ $httpBackend.whenGET('url1').respond('partial {{$parent.url}}');
+ $httpBackend.whenGET('url2').respond(404);
- expect($rootScope.$$childHead).toBeFalsy();
+ element = $compile('<ng:include src="url"></ng:include>')($rootScope);
+ expect(element.children().scope()).toBeFalsy();
- $rootScope.url = 'myUrl';
+ $rootScope.url = 'url1';
+ $rootScope.$digest();
+ $httpBackend.flush();
+ expect(element.children().scope()).toBeTruthy();
+ expect(element.text()).toBe('partial url1');
+
+ $rootScope.url = 'url2';
+ $rootScope.$digest();
+ $httpBackend.flush();
+ expect(element.children().scope()).toBeFalsy();
+ expect(element.text()).toBe('');
+
+ $rootScope.url = 'url1';
$rootScope.$digest();
- expect($rootScope.$$childHead).toBeTruthy();
+ expect(element.children().scope()).toBeTruthy();
$rootScope.url = null;
$rootScope.$digest();
- expect($rootScope.$$childHead).toBeFalsy();
+ expect(element.children().scope()).toBeFalsy();
}));