@@ -148,6 +148,36 @@ test( "wrapAll(String)", function() {
148
148
149
149
} ) ;
150
150
151
+ test ( "wrapAll(Function)" , 5 , function ( ) {
152
+ var prev = jQuery ( "#firstp" ) [ 0 ] . previousSibling ,
153
+ p = jQuery ( "#firstp,#first" ) [ 0 ] . parentNode ,
154
+ result = jQuery ( "#firstp,#first" ) . wrapAll ( function ( ) {
155
+ return "<div class='red'><div class='tmp'></div></div>" ;
156
+ } ) ;
157
+
158
+ equal ( result . parent ( ) . length , 1 , "Check for wrapping of on-the-fly html" ) ;
159
+ ok ( jQuery ( "#first" ) . parent ( ) . parent ( ) . is ( ".red" ) , "Check if wrapper has class 'red'" ) ;
160
+ ok ( jQuery ( "#firstp" ) . parent ( ) . parent ( ) . is ( ".red" ) , "Check if wrapper has class 'red'" ) ;
161
+ ok ( jQuery ( "#first" ) . parent ( ) . parent ( ) . parent ( ) . is ( p ) , "Correct Parent" ) ;
162
+ strictEqual ( jQuery ( "#first" ) . parent ( ) . parent ( ) [ 0 ] . previousSibling , prev , "Correct Previous Sibling" ) ;
163
+ } ) ;
164
+
165
+ test ( "wrapAll(Function) check execution characteristics" , 3 , function ( ) {
166
+ var i = 0 ;
167
+
168
+ jQuery ( "non-existent" ) . wrapAll ( function ( ) {
169
+ i ++ ;
170
+ return "" ;
171
+ } ) ;
172
+
173
+ ok ( ! i , "should not execute function argument if target element does not exist" ) ;
174
+
175
+ jQuery ( "#firstp" ) . wrapAll ( function ( index ) {
176
+ strictEqual ( this , jQuery ( "#firstp" ) [ 0 ] , "context must be the first found element" ) ;
177
+ strictEqual ( index , undefined , "index argument should not be included in function execution" ) ;
178
+ } ) ;
179
+ } ) ;
180
+
151
181
test ( "wrapAll(Element)" , function ( ) {
152
182
153
183
expect ( 3 ) ;
0 commit comments