@@ -1959,22 +1959,8 @@ QUnit.test( "find in document fragments", function( assert ) {
19591959 assert . strictEqual ( elem . length , 1 , "Selection works" ) ;
19601960} ) ;
19611961
1962- QUnit . test ( "jQuery.uniqueSort" , function ( assert ) {
1963- assert . expect ( 14 ) ;
1964-
1965- function Arrayish ( arr ) {
1966- var i = this . length = arr . length ;
1967- while ( i -- ) {
1968- this [ i ] = arr [ i ] ;
1969- }
1970- }
1971- Arrayish . prototype = {
1972- slice : [ ] . slice ,
1973- sort : [ ] . sort ,
1974- splice : [ ] . splice
1975- } ;
1976-
1977- var i , tests ,
1962+ function getUniqueSortFixtures ( ) {
1963+ var i ,
19781964 detached = [ ] ,
19791965 body = document . body ,
19801966 fixture = document . getElementById ( "qunit-fixture" ) ,
@@ -1989,7 +1975,7 @@ QUnit.test( "jQuery.uniqueSort", function( assert ) {
19891975 detached2 . appendChild ( document . createElement ( "li" ) ) . id = "detachedChild" + i ;
19901976 }
19911977
1992- tests = {
1978+ return {
19931979 "Empty" : {
19941980 input : [ ] ,
19951981 expected : [ ]
@@ -2030,15 +2016,63 @@ QUnit.test( "jQuery.uniqueSort", function( assert ) {
20302016 length : 3
20312017 }
20322018 } ;
2019+ }
2020+
2021+ QUnit . test ( "jQuery.uniqueSort" , function ( assert ) {
2022+ assert . expect ( 14 ) ;
2023+
2024+ var fixtures = getUniqueSortFixtures ( ) ;
2025+
2026+ function Arrayish ( arr ) {
2027+ var i = this . length = arr . length ;
2028+ while ( i -- ) {
2029+ this [ i ] = arr [ i ] ;
2030+ }
2031+ }
2032+ Arrayish . prototype = {
2033+ slice : [ ] . slice ,
2034+ sort : [ ] . sort ,
2035+ splice : [ ] . splice
2036+ } ;
20332037
2034- jQuery . each ( tests , function ( label , test ) {
2035- var length = test . length || test . input . length ;
2036- // We duplicate `test.input` because otherwise it is modified by `uniqueSort`
2038+ jQuery . each ( fixtures , function ( label , fixture ) {
2039+ var length = fixture . length || fixture . input . length ;
2040+
2041+ // We duplicate `fixture.input` because otherwise it is modified by `uniqueSort`
20372042 // and the second test becomes worthless.
2038- assert . deepEqual ( jQuery . uniqueSort ( test . input . slice ( 0 ) ) . slice ( 0 , length ) ,
2039- test . expected , label + " (array)" ) ;
2040- assert . deepEqual ( jQuery . uniqueSort ( new Arrayish ( test . input ) ) . slice ( 0 , length ) ,
2041- test . expected , label + " (quasi-array)" ) ;
2043+ assert . deepEqual (
2044+ jQuery . uniqueSort ( fixture . input . slice ( 0 ) )
2045+ . slice ( 0 , length ) ,
2046+ fixture . expected ,
2047+ label + " (array)"
2048+ ) ;
2049+
2050+ assert . deepEqual (
2051+ jQuery . uniqueSort ( new Arrayish ( fixture . input ) )
2052+ . slice ( 0 , length ) ,
2053+ fixture . expected ,
2054+ label + " (quasi-array)"
2055+ ) ;
2056+ } ) ;
2057+ } ) ;
2058+
2059+ QUnit . test ( "uniqueSort()" , function ( assert ) {
2060+ assert . expect ( 28 ) ;
2061+
2062+ var fixtures = getUniqueSortFixtures ( ) ;
2063+
2064+ jQuery . each ( fixtures , function ( label , fixture ) {
2065+ var length = fixture . length || fixture . input . length ,
2066+ fixtureInputCopy = fixture . input . slice ( 0 ) ,
2067+ sortedElem = jQuery ( fixture . input ) . uniqueSort ( ) ;
2068+
2069+ assert . deepEqual ( fixture . input , fixtureInputCopy , "Fixture not modified (" + label + ")" ) ;
2070+
2071+ assert . deepEqual ( sortedElem . slice ( 0 , length ) . toArray ( ) , fixture . expected , label ) ;
2072+
2073+ // Chaining
2074+ assert . ok ( sortedElem instanceof jQuery , "chaining" ) ;
2075+ assert . deepEqual ( sortedElem . end ( ) . toArray ( ) , fixture . input , label ) ;
20422076 } ) ;
20432077} ) ;
20442078
0 commit comments