Skip to content

Commit b930d14

Browse files
committed
Tests: partially use new qunit interface
http://qunitjs.com/upgrade-guide-2.x/ For most of the boring work was used https://github.com/apsdehal/qunit-migrate package However, it can't update local qunit helpers, plus in some places old QUnit.asyncTest signature is still used Fixes gh-2540
1 parent 9d820fb commit b930d14

24 files changed

+6198
-5941
lines changed

test/data/testinit.js

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -137,16 +137,20 @@ function url( value ) {
137137

138138
// Ajax testing helper
139139
this.ajaxTest = function( title, expect, options ) {
140-
var requestOptions;
141-
if ( jQuery.isFunction( options ) ) {
142-
options = options();
143-
}
144-
options = options || [];
145-
requestOptions = options.requests || options.request || options;
146-
if ( !jQuery.isArray( requestOptions ) ) {
147-
requestOptions = [ requestOptions ];
148-
}
149-
asyncTest( title, expect, function() {
140+
QUnit.test( title, expect, function( assert ) {
141+
var requestOptions;
142+
143+
if ( jQuery.isFunction( options ) ) {
144+
options = options( assert );
145+
}
146+
options = options || [];
147+
requestOptions = options.requests || options.request || options;
148+
if ( !jQuery.isArray( requestOptions ) ) {
149+
requestOptions = [ requestOptions ];
150+
}
151+
152+
var done = assert.async();
153+
150154
if ( options.setup ) {
151155
options.setup();
152156
}
@@ -160,7 +164,9 @@ this.ajaxTest = function( title, expect, options ) {
160164
if ( options.teardown ) {
161165
options.teardown();
162166
}
163-
start();
167+
168+
// Make sure all events will be called before done()
169+
setTimeout(done);
164170
}
165171
},
166172
requests = jQuery.map( requestOptions, function( options ) {
@@ -170,7 +176,7 @@ this.ajaxTest = function( title, expect, options ) {
170176
return function( _, status ) {
171177
if ( !completed ) {
172178
if ( !handler ) {
173-
ok( false, "unexpected " + status );
179+
assert.ok( false, "unexpected " + status );
174180
} else if ( jQuery.isFunction( handler ) ) {
175181
handler.apply( this, arguments );
176182
}
@@ -179,7 +185,7 @@ this.ajaxTest = function( title, expect, options ) {
179185
};
180186

181187
if ( options.afterSend ) {
182-
options.afterSend( request );
188+
options.afterSend( request, assert );
183189
}
184190

185191
return request
@@ -202,7 +208,8 @@ this.ajaxTest = function( title, expect, options ) {
202208
};
203209

204210
this.testIframe = function( fileName, name, fn ) {
205-
asyncTest(name, function() {
211+
QUnit.test(name, function( assert ) {
212+
var done = assert.async();
206213

207214
// load fixture in iframe
208215
var iframe = loadFixture(),
@@ -211,10 +218,9 @@ this.testIframe = function( fileName, name, fn ) {
211218
if ( win && win.jQuery && win.jQuery.isReady ) {
212219
clearInterval( interval );
213220

214-
start();
215-
216221
// call actual tests passing the correct jQuery instance to use
217-
fn.call( this, win.jQuery, win, win.document );
222+
fn.call( this, win.jQuery, win, win.document, assert );
223+
done();
218224
document.body.removeChild( iframe );
219225
iframe = null;
220226
}
@@ -233,11 +239,14 @@ this.testIframe = function( fileName, name, fn ) {
233239
};
234240

235241
this.testIframeWithCallback = function( title, fileName, func ) {
236-
asyncTest( title, 1, function() {
242+
QUnit.test( title, 1, function( assert ) {
237243
var iframe;
244+
var done = assert.async();
238245

239246
window.iframeCallback = function() {
240-
var args = arguments;
247+
var args = Array.prototype.slice.call( arguments );
248+
249+
args.push( assert );
241250

242251
setTimeout(function() {
243252
this.iframeCallback = undefined;
@@ -246,7 +255,7 @@ this.testIframeWithCallback = function( title, fileName, func ) {
246255
func.apply( this, args );
247256
func = function() {};
248257

249-
start();
258+
done();
250259
});
251260
};
252261
iframe = jQuery( "<div/>" ).css({ position: "absolute", width: "500px", left: "-600px" })

0 commit comments

Comments
 (0)