33describe ( 'jqLite' , function ( ) {
44 var scope , a , b , c , document ;
55
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+ }
619
720 beforeEach ( module ( provideLog ) ) ;
821
@@ -83,30 +96,27 @@ describe('jqLite', function() {
8396 } ) ;
8497
8598
86- // This is not working correctly in jQuery prior to v3.0 .
99+ // This is not working correctly in jQuery prior to v2.2 .
87100 // See https://github.com/jquery/jquery/issues/1987 for details.
88101 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 ;
91103
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 ;
96107
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 + '>' ) ;
100111
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 !' ) ;
104115
105- nodeNamesTested ++ ;
106- } ) ;
116+ nodeNamesTested ++ ;
117+ } ) ;
107118
108- expect ( nodeNamesTested ) . toBe ( 10 ) ;
109- }
119+ expect ( nodeNamesTested ) . toBe ( 10 ) ;
110120 } ) ;
111121
112122
@@ -712,11 +722,9 @@ describe('jqLite', function() {
712722 describe ( 'class' , function ( ) {
713723
714724 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 .
716726 // 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 ;
720728
721729 var svg = jqLite ( '<svg><rect></rect></svg>' ) ;
722730 var rect = svg . children ( ) ;
@@ -1023,12 +1031,10 @@ describe('jqLite', function() {
10231031 // See https://github.com/jquery/jquery/issues/2562 for more details.
10241032 // jqLite will align with jQuery 3.0 behavior in Angular 1.6.
10251033 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 ( ) ) {
10311035 val = null ;
1036+ } else {
1037+ val = [ ] ;
10321038 }
10331039
10341040 expect ( jqLite (
@@ -1070,7 +1076,8 @@ describe('jqLite', function() {
10701076
10711077 describe ( 'on' , function ( ) {
10721078 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+
10741081 var eventFn ;
10751082 var window = {
10761083 document : { } ,
@@ -1260,7 +1267,7 @@ describe('jqLite', function() {
12601267 } ) ;
12611268
12621269 it ( 'should fire mouseenter when coming from outside the browser window' , function ( ) {
1263- if ( window . jQuery ) return ;
1270+ if ( ! _jqLiteMode ) return ;
12641271
12651272 setup ( '<div>root<p>parent<span>child</span></p><ul></ul></div>' , 'p' , 'span' ) ;
12661273
@@ -1279,7 +1286,7 @@ describe('jqLite', function() {
12791286 } ) ;
12801287
12811288 it ( 'should fire the mousenter on SVG elements' , function ( ) {
1282- if ( window . jQuery ) return ;
1289+ if ( ! _jqLiteMode ) return ;
12831290
12841291 setup (
12851292 '<div>' +
@@ -1301,29 +1308,28 @@ describe('jqLite', function() {
13011308 } ) ;
13021309 } ) ;
13031310
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 ;
13121313
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 ( ) { } ;
13161319
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' ) ;
13201323
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' ) ;
13241327
1325- } ) ;
1326- }
1328+ expect ( function ( ) {
1329+ elm . on ( 'click' , aValue , callback ) ;
1330+ } ) . toThrowMinErr ( 'jqLite' , 'onargs' ) ;
1331+
1332+ } ) ;
13271333 } ) ;
13281334
13291335
@@ -1554,11 +1560,6 @@ describe('jqLite', function() {
15541560
15551561
15561562 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-
15621563 it ( 'should deregister the native listener when all jqLite listeners for given type are gone ' +
15631564 'after off("eventName", listener) call' , function ( ) {
15641565 var aElem = jqLite ( a ) ;
@@ -1571,7 +1572,7 @@ describe('jqLite', function() {
15711572
15721573 // jQuery <2.2 & jqLite pass the non-needed `false` useCapture parameter.
15731574 // See https://github.com/jquery/jquery/issues/2199 for details.
1574- if ( jQuery21 || _jqLiteMode ) {
1575+ if ( isJQuery21 ( ) || _jqLiteMode ) {
15751576 expect ( addEventListenerSpy ) . toHaveBeenCalledOnceWith ( 'click' , jasmine . any ( Function ) , false ) ;
15761577 } else {
15771578 expect ( addEventListenerSpy ) . toHaveBeenCalledOnceWith ( 'click' , jasmine . any ( Function ) ) ;
@@ -1580,7 +1581,7 @@ describe('jqLite', function() {
15801581 expect ( removeEventListenerSpy ) . not . toHaveBeenCalled ( ) ;
15811582
15821583 aElem . off ( 'click' , jqLiteListener ) ;
1583- if ( jQuery21 || _jqLiteMode ) {
1584+ if ( isJQuery21 ( ) || _jqLiteMode ) {
15841585 expect ( removeEventListenerSpy ) . toHaveBeenCalledOnceWith ( 'click' , nativeListenerFn , false ) ;
15851586 } else {
15861587 expect ( removeEventListenerSpy ) . toHaveBeenCalledOnceWith ( 'click' , nativeListenerFn ) ;
@@ -1596,7 +1597,7 @@ describe('jqLite', function() {
15961597 var nativeListenerFn ;
15971598
15981599 aElem . on ( 'click' , function ( ) { } ) ;
1599- if ( jQuery21 || _jqLiteMode ) {
1600+ if ( isJQuery21 ( ) || _jqLiteMode ) {
16001601 expect ( addEventListenerSpy ) . toHaveBeenCalledOnceWith ( 'click' , jasmine . any ( Function ) , false ) ;
16011602 } else {
16021603 expect ( addEventListenerSpy ) . toHaveBeenCalledOnceWith ( 'click' , jasmine . any ( Function ) ) ;
@@ -1605,7 +1606,7 @@ describe('jqLite', function() {
16051606 expect ( removeEventListenerSpy ) . not . toHaveBeenCalled ( ) ;
16061607
16071608 aElem . off ( 'click' ) ;
1608- if ( jQuery21 || _jqLiteMode ) {
1609+ if ( isJQuery21 ( ) || _jqLiteMode ) {
16091610 expect ( removeEventListenerSpy ) . toHaveBeenCalledOnceWith ( 'click' , nativeListenerFn , false ) ;
16101611 } else {
16111612 expect ( removeEventListenerSpy ) . toHaveBeenCalledOnceWith ( 'click' , nativeListenerFn ) ;
@@ -1621,7 +1622,7 @@ describe('jqLite', function() {
16211622 var nativeListenerFn ;
16221623
16231624 aElem . on ( 'click' , function ( ) { } ) ;
1624- if ( jQuery21 || _jqLiteMode ) {
1625+ if ( isJQuery21 ( ) || _jqLiteMode ) {
16251626 expect ( addEventListenerSpy ) . toHaveBeenCalledOnceWith ( 'click' , jasmine . any ( Function ) , false ) ;
16261627 } else {
16271628 expect ( addEventListenerSpy ) . toHaveBeenCalledOnceWith ( 'click' , jasmine . any ( Function ) ) ;
@@ -1630,7 +1631,7 @@ describe('jqLite', function() {
16301631 addEventListenerSpy . calls . reset ( ) ;
16311632
16321633 aElem . on ( 'dblclick' , function ( ) { } ) ;
1633- if ( jQuery21 || _jqLiteMode ) {
1634+ if ( isJQuery21 ( ) || _jqLiteMode ) {
16341635 expect ( addEventListenerSpy ) . toHaveBeenCalledOnceWith ( 'dblclick' , nativeListenerFn , false ) ;
16351636 } else {
16361637 expect ( addEventListenerSpy ) . toHaveBeenCalledOnceWith ( 'dblclick' , nativeListenerFn ) ;
@@ -1640,7 +1641,7 @@ describe('jqLite', function() {
16401641
16411642 aElem . off ( 'click dblclick' ) ;
16421643
1643- if ( jQuery21 || _jqLiteMode ) {
1644+ if ( isJQuery21 ( ) || _jqLiteMode ) {
16441645 expect ( removeEventListenerSpy ) . toHaveBeenCalledWith ( 'click' , nativeListenerFn , false ) ;
16451646 expect ( removeEventListenerSpy ) . toHaveBeenCalledWith ( 'dblclick' , nativeListenerFn , false ) ;
16461647 } else {
@@ -1659,7 +1660,7 @@ describe('jqLite', function() {
16591660 var nativeListenerFn ;
16601661
16611662 aElem . on ( 'click' , function ( ) { } ) ;
1662- if ( jQuery21 || _jqLiteMode ) {
1663+ if ( isJQuery21 ( ) || _jqLiteMode ) {
16631664 expect ( addEventListenerSpy ) . toHaveBeenCalledOnceWith ( 'click' , jasmine . any ( Function ) , false ) ;
16641665 } else {
16651666 expect ( addEventListenerSpy ) . toHaveBeenCalledOnceWith ( 'click' , jasmine . any ( Function ) ) ;
@@ -1668,15 +1669,15 @@ describe('jqLite', function() {
16681669 addEventListenerSpy . calls . reset ( ) ;
16691670
16701671 aElem . on ( 'dblclick' , function ( ) { } ) ;
1671- if ( jQuery21 || _jqLiteMode ) {
1672+ if ( isJQuery21 ( ) || _jqLiteMode ) {
16721673 expect ( addEventListenerSpy ) . toHaveBeenCalledOnceWith ( 'dblclick' , nativeListenerFn , false ) ;
16731674 } else {
16741675 expect ( addEventListenerSpy ) . toHaveBeenCalledOnceWith ( 'dblclick' , nativeListenerFn ) ;
16751676 }
16761677
16771678 aElem . off ( ) ;
16781679
1679- if ( jQuery21 || _jqLiteMode ) {
1680+ if ( isJQuery21 ( ) || _jqLiteMode ) {
16801681 expect ( removeEventListenerSpy ) . toHaveBeenCalledWith ( 'click' , nativeListenerFn , false ) ;
16811682 expect ( removeEventListenerSpy ) . toHaveBeenCalledWith ( 'dblclick' , nativeListenerFn , false ) ;
16821683 } else {
@@ -1688,16 +1689,15 @@ describe('jqLite', function() {
16881689 } ) ;
16891690
16901691
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+ } ) ;
17011701 } ) ;
17021702
17031703 describe ( 'one' , function ( ) {
0 commit comments