@@ -1375,7 +1375,7 @@ describe('$compile', function() {
1375
1375
return function ( scope , element ) {
1376
1376
iscope = scope ;
1377
1377
log ( scope . $id ) ;
1378
- expect ( element . data ( '$isolateScope ' ) ) . toBe ( scope ) ;
1378
+ expect ( element . data ( '$isolateScopeNoTemplate ' ) ) . toBe ( scope ) ;
1379
1379
} ;
1380
1380
}
1381
1381
} ;
@@ -1522,7 +1522,7 @@ describe('$compile', function() {
1522
1522
) ;
1523
1523
1524
1524
1525
- it ( 'should allow more one new scope directives per element, but directives should share' +
1525
+ it ( 'should allow more than one new scope directives per element, but directives should share' +
1526
1526
'the scope' , inject (
1527
1527
function ( $rootScope , $compile , log ) {
1528
1528
element = $compile ( '<div class="scope-a; scope-b"></div>' ) ( $rootScope ) ;
@@ -1554,6 +1554,120 @@ describe('$compile', function() {
1554
1554
expect ( log ) . toEqual ( '002' ) ;
1555
1555
} )
1556
1556
) ;
1557
+
1558
+
1559
+ describe ( 'scope()/isolate() scope getters' , function ( ) {
1560
+
1561
+ describe ( 'with no directives' , function ( ) {
1562
+
1563
+ it ( 'should return the scope of the parent node' , inject (
1564
+ function ( $rootScope , $compile ) {
1565
+ element = $compile ( '<div></div>' ) ( $rootScope ) ;
1566
+ expect ( element . scope ( ) ) . toBe ( $rootScope ) ;
1567
+ } )
1568
+ ) ;
1569
+ } ) ;
1570
+
1571
+
1572
+ describe ( 'with new scope directives' , function ( ) {
1573
+
1574
+ it ( 'should return the new scope at the directive element' , inject (
1575
+ function ( $rootScope , $compile ) {
1576
+ element = $compile ( '<div scope></div>' ) ( $rootScope ) ;
1577
+ expect ( element . scope ( ) . $parent ) . toBe ( $rootScope ) ;
1578
+ } )
1579
+ ) ;
1580
+
1581
+
1582
+ it ( 'should return the new scope for children in the original template' , inject (
1583
+ function ( $rootScope , $compile ) {
1584
+ element = $compile ( '<div scope><a></a></div>' ) ( $rootScope ) ;
1585
+ expect ( element . find ( 'a' ) . scope ( ) . $parent ) . toBe ( $rootScope ) ;
1586
+ } )
1587
+ ) ;
1588
+
1589
+
1590
+ it ( 'should return the new scope for children in the directive template' , inject (
1591
+ function ( $rootScope , $compile , $httpBackend ) {
1592
+ $httpBackend . expect ( 'GET' , 'tscope.html' ) . respond ( '<a></a>' ) ;
1593
+ element = $compile ( '<div tscope></div>' ) ( $rootScope ) ;
1594
+ $httpBackend . flush ( ) ;
1595
+ expect ( element . find ( 'a' ) . scope ( ) . $parent ) . toBe ( $rootScope ) ;
1596
+ } )
1597
+ ) ;
1598
+ } ) ;
1599
+
1600
+
1601
+ describe ( 'with isolate scope directives' , function ( ) {
1602
+
1603
+ it ( 'should return the root scope for directives at the root element' , inject (
1604
+ function ( $rootScope , $compile ) {
1605
+ element = $compile ( '<div iscope></div>' ) ( $rootScope ) ;
1606
+ expect ( element . scope ( ) ) . toBe ( $rootScope ) ;
1607
+ } )
1608
+ ) ;
1609
+
1610
+
1611
+ it ( 'should return the non-isolate scope at the directive element' , inject (
1612
+ function ( $rootScope , $compile ) {
1613
+ var directiveElement ;
1614
+ element = $compile ( '<div><div iscope></div></div>' ) ( $rootScope ) ;
1615
+ directiveElement = element . children ( ) ;
1616
+ expect ( directiveElement . scope ( ) ) . toBe ( $rootScope ) ;
1617
+ expect ( directiveElement . isolateScope ( ) . $parent ) . toBe ( $rootScope ) ;
1618
+ } )
1619
+ ) ;
1620
+
1621
+
1622
+ it ( 'should return the isolate scope for children in the original template' , inject (
1623
+ function ( $rootScope , $compile ) {
1624
+ element = $compile ( '<div iscope><a></a></div>' ) ( $rootScope ) ;
1625
+ expect ( element . find ( 'a' ) . scope ( ) ) . toBe ( $rootScope ) ; //xx
1626
+ } )
1627
+ ) ;
1628
+
1629
+
1630
+ it ( 'should return the isolate scope for children in directive template' , inject (
1631
+ function ( $rootScope , $compile , $httpBackend ) {
1632
+ $httpBackend . expect ( 'GET' , 'tiscope.html' ) . respond ( '<a></a>' ) ;
1633
+ element = $compile ( '<div tiscope></div>' ) ( $rootScope ) ;
1634
+ expect ( element . isolateScope ( ) ) . toBeUndefined ( ) ; // this is the current behavior, not desired feature
1635
+ $httpBackend . flush ( ) ;
1636
+ expect ( element . find ( 'a' ) . scope ( ) ) . toBe ( element . isolateScope ( ) ) ;
1637
+ expect ( element . isolateScope ( ) ) . not . toBe ( $rootScope ) ;
1638
+ } )
1639
+ ) ;
1640
+ } ) ;
1641
+
1642
+
1643
+ describe ( 'with isolate scope directives and directives that manually create a new scope' , function ( ) {
1644
+
1645
+ it ( 'should return the new scope at the directive element' , inject (
1646
+ function ( $rootScope , $compile ) {
1647
+ var directiveElement ;
1648
+ element = $compile ( '<div><a ng-if="true" iscope></a></div>' ) ( $rootScope ) ;
1649
+ $rootScope . $apply ( ) ;
1650
+ directiveElement = element . find ( 'a' ) ;
1651
+ expect ( directiveElement . scope ( ) . $parent ) . toBe ( $rootScope ) ;
1652
+ expect ( directiveElement . scope ( ) ) . not . toBe ( directiveElement . isolateScope ( ) ) ;
1653
+ } )
1654
+ ) ;
1655
+
1656
+
1657
+ it ( 'should return the isolate scope for child elements' , inject (
1658
+ function ( $rootScope , $compile , $httpBackend ) {
1659
+ var directiveElement , child ;
1660
+ $httpBackend . expect ( 'GET' , 'tiscope.html' ) . respond ( '<span></span>' ) ;
1661
+ element = $compile ( '<div><a ng-if="true" tiscope></a></div>' ) ( $rootScope ) ;
1662
+ $rootScope . $apply ( ) ;
1663
+ $httpBackend . flush ( ) ;
1664
+ directiveElement = element . find ( 'a' ) ;
1665
+ child = directiveElement . find ( 'span' ) ;
1666
+ expect ( child . scope ( ) ) . toBe ( directiveElement . isolateScope ( ) ) ;
1667
+ } )
1668
+ ) ;
1669
+ } ) ;
1670
+ } ) ;
1557
1671
} ) ;
1558
1672
} ) ;
1559
1673
} ) ;
@@ -2121,6 +2235,7 @@ describe('$compile', function() {
2121
2235
} ) ;
2122
2236
} ) ) ;
2123
2237
2238
+
2124
2239
it ( 'should give other directives the parent scope' , inject ( function ( $rootScope ) {
2125
2240
compile ( '<div><input type="text" my-component store-scope ng-model="value"></div>' ) ;
2126
2241
$rootScope . $apply ( function ( ) {
@@ -2131,6 +2246,7 @@ describe('$compile', function() {
2131
2246
expect ( componentScope . $parent ) . toBe ( regularScope )
2132
2247
} ) ) ;
2133
2248
2249
+
2134
2250
it ( 'should not give the isolate scope to other directive template' , function ( ) {
2135
2251
module ( function ( ) {
2136
2252
directive ( 'otherTplDir' , function ( ) {
0 commit comments