3
3
describe ( 'jqLite' , function ( ) {
4
4
var scope , a , b , c , document ;
5
5
6
+ // Checks if jQuery 2.1 is used.
7
+ function isJQuery21 ( ) {
8
+ if ( _jqLiteMode ) return false ;
9
+ var jQueryVersionParts = _jQuery . fn . jquery . split ( '.' ) ;
10
+ return jQueryVersionParts [ 0 ] + '.' + jQueryVersionParts [ 1 ] === '2.1' ;
11
+ }
12
+
13
+ // Checks if jQuery 2.x is used.
14
+ function isJQuery2x ( ) {
15
+ if ( _jqLiteMode ) return false ;
16
+ var jQueryVersionParts = _jQuery . fn . jquery . split ( '.' ) ;
17
+ return jQueryVersionParts [ 0 ] === '2' ;
18
+ }
6
19
7
20
beforeEach ( module ( provideLog ) ) ;
8
21
@@ -83,30 +96,27 @@ describe('jqLite', function() {
83
96
} ) ;
84
97
85
98
86
- // This is not working correctly in jQuery prior to v3.0 .
99
+ // This is not working correctly in jQuery prior to v2.2 .
87
100
// See https://github.com/jquery/jquery/issues/1987 for details.
88
101
it ( 'should properly handle dash-delimited node names' , function ( ) {
89
- var jQueryVersion = window . jQuery && window . jQuery . fn . jquery . split ( '.' ) [ 0 ] ;
90
- var jQuery3xOrNewer = jQueryVersion && ( Number ( jQueryVersion ) >= 3 ) ;
102
+ if ( isJQuery21 ( ) ) return ;
91
103
92
- if ( _jqLiteMode || jQuery3xOrNewer ) {
93
- var nodeNames = 'thead tbody tfoot colgroup caption tr th td div kung' . split ( ' ' ) ;
94
- var nodeNamesTested = 0 ;
95
- var nodes , customNodeName ;
104
+ var nodeNames = 'thead tbody tfoot colgroup caption tr th td div kung' . split ( ' ' ) ;
105
+ var nodeNamesTested = 0 ;
106
+ var nodes , customNodeName ;
96
107
97
- forEach ( nodeNames , function ( nodeName ) {
98
- var customNodeName = nodeName + '-foo' ;
99
- var nodes = jqLite ( '<' + customNodeName + '>Hello, world !</' + customNodeName + '>' ) ;
108
+ forEach ( nodeNames , function ( nodeName ) {
109
+ var customNodeName = nodeName + '-foo' ;
110
+ var nodes = jqLite ( '<' + customNodeName + '>Hello, world !</' + customNodeName + '>' ) ;
100
111
101
- expect ( nodes . length ) . toBe ( 1 ) ;
102
- expect ( nodeName_ ( nodes ) ) . toBe ( customNodeName ) ;
103
- expect ( nodes . html ( ) ) . toBe ( 'Hello, world !' ) ;
112
+ expect ( nodes . length ) . toBe ( 1 ) ;
113
+ expect ( nodeName_ ( nodes ) ) . toBe ( customNodeName ) ;
114
+ expect ( nodes . html ( ) ) . toBe ( 'Hello, world !' ) ;
104
115
105
- nodeNamesTested ++ ;
106
- } ) ;
116
+ nodeNamesTested ++ ;
117
+ } ) ;
107
118
108
- expect ( nodeNamesTested ) . toBe ( 10 ) ;
109
- }
119
+ expect ( nodeNamesTested ) . toBe ( 10 ) ;
110
120
} ) ;
111
121
112
122
@@ -712,11 +722,9 @@ describe('jqLite', function() {
712
722
describe ( 'class' , function ( ) {
713
723
714
724
it ( 'should properly do with SVG elements' , function ( ) {
715
- // This is not working correctly in jQuery prior to v3.0 .
725
+ // This is not working correctly in jQuery prior to v2.2 .
716
726
// See https://github.com/jquery/jquery/issues/2199 for details.
717
- var jQueryVersion = window . jQuery && window . jQuery . fn . jquery . split ( '.' ) [ 0 ] ;
718
- var jQuery3xOrNewer = jQueryVersion && ( Number ( jQueryVersion ) >= 3 ) ;
719
- if ( ! _jqLiteMode && ! jQuery3xOrNewer ) return ;
727
+ if ( isJQuery21 ( ) ) return ;
720
728
721
729
var svg = jqLite ( '<svg><rect></rect></svg>' ) ;
722
730
var rect = svg . children ( ) ;
@@ -1023,12 +1031,10 @@ describe('jqLite', function() {
1023
1031
// See https://github.com/jquery/jquery/issues/2562 for more details.
1024
1032
// jqLite will align with jQuery 3.0 behavior in Angular 1.6.
1025
1033
var val ;
1026
- var jQueryVersion = window . jQuery && window . jQuery . fn . jquery . split ( '.' ) [ 0 ] ;
1027
- var jQuery3xOrNewer = jQueryVersion && ( Number ( jQueryVersion ) >= 3 ) ;
1028
- if ( ! _jqLiteMode && jQuery3xOrNewer ) {
1029
- val = [ ] ;
1030
- } else {
1034
+ if ( _jqLiteMode || isJQuery2x ( ) ) {
1031
1035
val = null ;
1036
+ } else {
1037
+ val = [ ] ;
1032
1038
}
1033
1039
1034
1040
expect ( jqLite (
@@ -1070,7 +1076,8 @@ describe('jqLite', function() {
1070
1076
1071
1077
describe ( 'on' , function ( ) {
1072
1078
it ( 'should bind to window on hashchange' , function ( ) {
1073
- if ( jqLite . fn ) return ; // don't run in jQuery
1079
+ if ( ! _jqLiteMode ) return ; // don't run in jQuery
1080
+
1074
1081
var eventFn ;
1075
1082
var window = {
1076
1083
document : { } ,
@@ -1260,7 +1267,7 @@ describe('jqLite', function() {
1260
1267
} ) ;
1261
1268
1262
1269
it ( 'should fire mouseenter when coming from outside the browser window' , function ( ) {
1263
- if ( window . jQuery ) return ;
1270
+ if ( ! _jqLiteMode ) return ;
1264
1271
1265
1272
setup ( '<div>root<p>parent<span>child</span></p><ul></ul></div>' , 'p' , 'span' ) ;
1266
1273
@@ -1279,7 +1286,7 @@ describe('jqLite', function() {
1279
1286
} ) ;
1280
1287
1281
1288
it ( 'should fire the mousenter on SVG elements' , function ( ) {
1282
- if ( window . jQuery ) return ;
1289
+ if ( ! _jqLiteMode ) return ;
1283
1290
1284
1291
setup (
1285
1292
'<div>' +
@@ -1301,29 +1308,28 @@ describe('jqLite', function() {
1301
1308
} ) ;
1302
1309
} ) ;
1303
1310
1304
- // Only run this test for jqLite and not normal jQuery
1305
- if ( _jqLiteMode ) {
1306
- it ( 'should throw an error if eventData or a selector is passed' , function ( ) {
1307
- var elm = jqLite ( a ) ,
1308
- anObj = { } ,
1309
- aString = '' ,
1310
- aValue = 45 ,
1311
- callback = function ( ) { } ;
1311
+ it ( 'should throw an error if eventData or a selector is passed' , function ( ) {
1312
+ if ( ! _jqLiteMode ) return ;
1312
1313
1313
- expect ( function ( ) {
1314
- elm . on ( 'click' , anObj , callback ) ;
1315
- } ) . toThrowMinErr ( 'jqLite' , 'onargs' ) ;
1314
+ var elm = jqLite ( a ) ,
1315
+ anObj = { } ,
1316
+ aString = '' ,
1317
+ aValue = 45 ,
1318
+ callback = function ( ) { } ;
1316
1319
1317
- expect ( function ( ) {
1318
- elm . on ( 'click' , null , aString , callback ) ;
1319
- } ) . toThrowMinErr ( 'jqLite' , 'onargs' ) ;
1320
+ expect ( function ( ) {
1321
+ elm . on ( 'click' , anObj , callback ) ;
1322
+ } ) . toThrowMinErr ( 'jqLite' , 'onargs' ) ;
1320
1323
1321
- expect ( function ( ) {
1322
- elm . on ( 'click' , aValue , callback ) ;
1323
- } ) . toThrowMinErr ( 'jqLite' , 'onargs' ) ;
1324
+ expect ( function ( ) {
1325
+ elm . on ( 'click' , null , aString , callback ) ;
1326
+ } ) . toThrowMinErr ( 'jqLite' , 'onargs' ) ;
1324
1327
1325
- } ) ;
1326
- }
1328
+ expect ( function ( ) {
1329
+ elm . on ( 'click' , aValue , callback ) ;
1330
+ } ) . toThrowMinErr ( 'jqLite' , 'onargs' ) ;
1331
+
1332
+ } ) ;
1327
1333
} ) ;
1328
1334
1329
1335
@@ -1554,11 +1560,6 @@ describe('jqLite', function() {
1554
1560
1555
1561
1556
1562
describe ( 'native listener deregistration' , function ( ) {
1557
- var jQueryVersionString = window . jQuery && window . jQuery . fn . jquery ;
1558
- var jQueryMajor = jQueryVersionString && Number ( jQueryVersionString . split ( '.' ) [ 0 ] ) ;
1559
- var jQueryMinor = jQueryVersionString && Number ( jQueryVersionString . split ( '.' ) [ 1 ] ) ;
1560
- var jQuery21 = jQueryMajor === 2 && jQueryMinor === 1 ;
1561
-
1562
1563
it ( 'should deregister the native listener when all jqLite listeners for given type are gone ' +
1563
1564
'after off("eventName", listener) call' , function ( ) {
1564
1565
var aElem = jqLite ( a ) ;
@@ -1571,7 +1572,7 @@ describe('jqLite', function() {
1571
1572
1572
1573
// jQuery <2.2 passes the non-needed `false` useCapture parameter.
1573
1574
// See https://github.com/jquery/jquery/issues/2199 for details.
1574
- if ( jQuery21 ) {
1575
+ if ( isJQuery21 ( ) ) {
1575
1576
expect ( addEventListenerSpy ) . toHaveBeenCalledOnceWith ( 'click' , jasmine . any ( Function ) , false ) ;
1576
1577
} else {
1577
1578
expect ( addEventListenerSpy ) . toHaveBeenCalledOnceWith ( 'click' , jasmine . any ( Function ) ) ;
@@ -1580,7 +1581,7 @@ describe('jqLite', function() {
1580
1581
expect ( removeEventListenerSpy ) . not . toHaveBeenCalled ( ) ;
1581
1582
1582
1583
aElem . off ( 'click' , jqLiteListener ) ;
1583
- if ( jQuery21 ) {
1584
+ if ( isJQuery21 ( ) ) {
1584
1585
expect ( removeEventListenerSpy ) . toHaveBeenCalledOnceWith ( 'click' , nativeListenerFn , false ) ;
1585
1586
} else {
1586
1587
expect ( removeEventListenerSpy ) . toHaveBeenCalledOnceWith ( 'click' , nativeListenerFn ) ;
@@ -1596,7 +1597,7 @@ describe('jqLite', function() {
1596
1597
var nativeListenerFn ;
1597
1598
1598
1599
aElem . on ( 'click' , function ( ) { } ) ;
1599
- if ( jQuery21 ) {
1600
+ if ( isJQuery21 ( ) ) {
1600
1601
expect ( addEventListenerSpy ) . toHaveBeenCalledOnceWith ( 'click' , jasmine . any ( Function ) , false ) ;
1601
1602
} else {
1602
1603
expect ( addEventListenerSpy ) . toHaveBeenCalledOnceWith ( 'click' , jasmine . any ( Function ) ) ;
@@ -1605,7 +1606,7 @@ describe('jqLite', function() {
1605
1606
expect ( removeEventListenerSpy ) . not . toHaveBeenCalled ( ) ;
1606
1607
1607
1608
aElem . off ( 'click' ) ;
1608
- if ( jQuery21 ) {
1609
+ if ( isJQuery21 ( ) ) {
1609
1610
expect ( removeEventListenerSpy ) . toHaveBeenCalledOnceWith ( 'click' , nativeListenerFn , false ) ;
1610
1611
} else {
1611
1612
expect ( removeEventListenerSpy ) . toHaveBeenCalledOnceWith ( 'click' , nativeListenerFn ) ;
@@ -1621,7 +1622,7 @@ describe('jqLite', function() {
1621
1622
var nativeListenerFn ;
1622
1623
1623
1624
aElem . on ( 'click' , function ( ) { } ) ;
1624
- if ( jQuery21 ) {
1625
+ if ( isJQuery21 ( ) ) {
1625
1626
expect ( addEventListenerSpy ) . toHaveBeenCalledOnceWith ( 'click' , jasmine . any ( Function ) , false ) ;
1626
1627
} else {
1627
1628
expect ( addEventListenerSpy ) . toHaveBeenCalledOnceWith ( 'click' , jasmine . any ( Function ) ) ;
@@ -1630,7 +1631,7 @@ describe('jqLite', function() {
1630
1631
addEventListenerSpy . calls . reset ( ) ;
1631
1632
1632
1633
aElem . on ( 'dblclick' , function ( ) { } ) ;
1633
- if ( jQuery21 ) {
1634
+ if ( isJQuery21 ( ) ) {
1634
1635
expect ( addEventListenerSpy ) . toHaveBeenCalledOnceWith ( 'dblclick' , nativeListenerFn , false ) ;
1635
1636
} else {
1636
1637
expect ( addEventListenerSpy ) . toHaveBeenCalledOnceWith ( 'dblclick' , nativeListenerFn ) ;
@@ -1640,7 +1641,7 @@ describe('jqLite', function() {
1640
1641
1641
1642
aElem . off ( 'click dblclick' ) ;
1642
1643
1643
- if ( jQuery21 ) {
1644
+ if ( isJQuery21 ( ) ) {
1644
1645
expect ( removeEventListenerSpy ) . toHaveBeenCalledWith ( 'click' , nativeListenerFn , false ) ;
1645
1646
expect ( removeEventListenerSpy ) . toHaveBeenCalledWith ( 'dblclick' , nativeListenerFn , false ) ;
1646
1647
} else {
@@ -1659,7 +1660,7 @@ describe('jqLite', function() {
1659
1660
var nativeListenerFn ;
1660
1661
1661
1662
aElem . on ( 'click' , function ( ) { } ) ;
1662
- if ( jQuery21 ) {
1663
+ if ( isJQuery21 ( ) ) {
1663
1664
expect ( addEventListenerSpy ) . toHaveBeenCalledOnceWith ( 'click' , jasmine . any ( Function ) , false ) ;
1664
1665
} else {
1665
1666
expect ( addEventListenerSpy ) . toHaveBeenCalledOnceWith ( 'click' , jasmine . any ( Function ) ) ;
@@ -1668,15 +1669,15 @@ describe('jqLite', function() {
1668
1669
addEventListenerSpy . calls . reset ( ) ;
1669
1670
1670
1671
aElem . on ( 'dblclick' , function ( ) { } ) ;
1671
- if ( jQuery21 ) {
1672
+ if ( isJQuery21 ( ) ) {
1672
1673
expect ( addEventListenerSpy ) . toHaveBeenCalledOnceWith ( 'dblclick' , nativeListenerFn , false ) ;
1673
1674
} else {
1674
1675
expect ( addEventListenerSpy ) . toHaveBeenCalledOnceWith ( 'dblclick' , nativeListenerFn ) ;
1675
1676
}
1676
1677
1677
1678
aElem . off ( ) ;
1678
1679
1679
- if ( jQuery21 ) {
1680
+ if ( isJQuery21 ( ) ) {
1680
1681
expect ( removeEventListenerSpy ) . toHaveBeenCalledWith ( 'click' , nativeListenerFn , false ) ;
1681
1682
expect ( removeEventListenerSpy ) . toHaveBeenCalledWith ( 'dblclick' , nativeListenerFn , false ) ;
1682
1683
} else {
@@ -1688,16 +1689,15 @@ describe('jqLite', function() {
1688
1689
} ) ;
1689
1690
1690
1691
1691
- // Only run this test for jqLite and not normal jQuery
1692
- if ( _jqLiteMode ) {
1693
- it ( 'should throw an error if a selector is passed' , function ( ) {
1694
- var aElem = jqLite ( a ) ;
1695
- aElem . on ( 'click' , noop ) ;
1696
- expect ( function ( ) {
1697
- aElem . off ( 'click' , noop , '.test' ) ;
1698
- } ) . toThrowError ( / \[ j q L i t e : o f f a r g s \] / ) ;
1699
- } ) ;
1700
- }
1692
+ it ( 'should throw an error if a selector is passed' , function ( ) {
1693
+ if ( ! _jqLiteMode ) return ;
1694
+
1695
+ var aElem = jqLite ( a ) ;
1696
+ aElem . on ( 'click' , noop ) ;
1697
+ expect ( function ( ) {
1698
+ aElem . off ( 'click' , noop , '.test' ) ;
1699
+ } ) . toThrowError ( / \[ j q L i t e : o f f a r g s \] / ) ;
1700
+ } ) ;
1701
1701
} ) ;
1702
1702
1703
1703
describe ( 'one' , function ( ) {
0 commit comments