X Tutup
Skip to content

Commit 517846a

Browse files
committed
No ticket: speedup test suite. Close jquerygh-1020.
1 parent 8773067 commit 517846a

File tree

4 files changed

+223
-264
lines changed

4 files changed

+223
-264
lines changed

test/unit/ajax.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,9 +1481,7 @@
14811481
jQuery.getScript( url("data/test.js"), function( data, _, jqXHR ) {
14821482
equal( foobar, "bar", "Check if script was evaluated" );
14831483
strictEqual( data, jqXHR.responseText, "Same-domain script requests returns the source of the script (#8082)" );
1484-
setTimeout(function() {
1485-
start();
1486-
}, 1000 );
1484+
start();
14871485
});
14881486
});
14891487

@@ -2221,7 +2219,7 @@
22212219
test( "jQuery.ajaxSetup({timeout: Number}) - with global timeout", function() {
22222220
var passed = 0;
22232221

2224-
expect( 1 );
2222+
expect( 2 );
22252223

22262224
stop();
22272225

@@ -2230,9 +2228,8 @@
22302228
});
22312229

22322230
var pass = function() {
2233-
passed++;
2231+
ok( passed++ < 2, "Error callback executed" );
22342232
if ( passed == 2 ) {
2235-
ok( true, "Check local and global callbacks after timeout" );
22362233
jQuery("#qunit-fixture").unbind("ajaxError");
22372234
start();
22382235
}

test/unit/effects.js

Lines changed: 72 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -695,14 +695,13 @@ test("stop(clearQueue, gotoEnd)", function() {
695695

696696
asyncTest( "stop( queue, ..., ... ) - Stop single queues", function() {
697697
expect( 3 );
698-
var foo = jQuery( "#foo" ),
699-
saved;
698+
var saved,
699+
foo = jQuery("#foo").css({ width: 200, height: 200 });
700700

701-
foo.css( "width", 200 ).css( "height", 200 );
702701
foo.animate({
703702
width: 400
704703
},{
705-
duration: 1000,
704+
duration: 500,
706705
complete: function() {
707706
equal( parseFloat( foo.css("width") ), 400, "Animation completed for standard queue" );
708707
equal( parseFloat( foo.css("height") ), saved, "Height was not changed after the second stop");
@@ -715,7 +714,7 @@ asyncTest( "stop( queue, ..., ... ) - Stop single queues", function() {
715714
},{
716715
duration: 1000,
717716
queue: "height"
718-
}).dequeue( "height" ).stop( "height", false, true );
717+
}).dequeue("height").stop( "height", false, true );
719718

720719
equal( parseFloat( foo.css("height") ), 400, "Height was stopped with gotoEnd" );
721720

@@ -745,16 +744,6 @@ test("toggle()", function() {
745744
ok( x.is(":visible"), "is visible again" );
746745
});
747746

748-
jQuery.checkOverflowDisplay = function(){
749-
var o = jQuery.css( this, "overflow" );
750-
751-
equal(o, "visible", "Overflow should be visible: " + o);
752-
equal(jQuery.css( this, "display" ), "inline", "Display shouldn't be tampered with.");
753-
754-
jQuery(this).remove();
755-
start();
756-
};
757-
758747
test( "jQuery.fx.prototype.cur() - <1.8 Back Compat", 7, function() {
759748
var div = jQuery( "<div></div>" ).appendTo( "#qunit-fixture" ).css({
760749
color: "#ABC",
@@ -809,29 +798,31 @@ test( "jQuery.fx.prototype.cur() - <1.8 Back Compat", 7, function() {
809798
jQuery( div ).remove();
810799
});
811800

812-
test("JS Overflow and Display", function() {
813-
expect(2);
801+
test("Overflow and Display", function() {
802+
expect(4);
814803
stop();
815-
jQuery.makeTest( "JS Overflow and Display" )
816-
.addClass("widewidth")
817-
.css({ overflow: "visible", display: "inline" })
818-
.addClass("widewidth")
819-
.text("Some sample text.")
820-
.before("text before")
821-
.after("text after")
822-
.animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
823-
});
824804

825-
test("CSS Overflow and Display", function() {
826-
expect(2);
827-
stop();
828-
jQuery.makeTest( "CSS Overflow and Display" )
829-
.addClass("overflow inline")
805+
var
806+
testClass = jQuery.makeTest("Overflow and Display")
807+
.addClass("overflow inline"),
808+
testStyle = jQuery.makeTest("Overflow and Display (inline style)")
809+
.css({ overflow: "visible", display: "inline" }),
810+
remaining = 2,
811+
done = function() {
812+
equal( jQuery.css( this, "overflow" ), "visible", "Overflow should be 'visible'" );
813+
equal( jQuery.css( this, "display" ), "inline", "Display should be 'inline'" );
814+
815+
if ( --remaining === 0 ) {
816+
start();
817+
}
818+
};
819+
820+
testClass.add( testStyle )
830821
.addClass("widewidth")
831822
.text("Some sample text.")
832823
.before("text before")
833824
.after("text after")
834-
.animate({ opacity: 0.5 }, "slow", jQuery.checkOverflowDisplay);
825+
.animate({ opacity: 0.5 }, "slow", done );
835826
});
836827

837828
jQuery.each({
@@ -1126,57 +1117,63 @@ test("jQuery.show('fast') doesn't clear radio buttons (bug #1095)", function ()
11261117
});
11271118
});
11281119

1129-
jQuery.expandedEach = jQuery.each;
1130-
jQuery.expandedEach({
1131-
"slideToggle": function( $elem ) {
1132-
return parseFloat( $elem.css("height") );
1133-
},
1134-
"fadeToggle": function( $elem ) {
1135-
return $elem.css("opacity");
1136-
},
1137-
"toggle": function( $elem ) {
1138-
return parseFloat( $elem.css("width") );
1139-
}
1140-
},
1141-
function( method, defProp ) {
1142-
test( method + "().stop()." + method + "()", function() {
1143-
expect( 8 );
1120+
test( "interrupt toggle", function() {
1121+
expect( 24 );
1122+
stop();
11441123

1145-
var animTime = 2000;
1124+
var longDuration = 2000,
1125+
shortDuration = 500,
1126+
remaining = 0,
1127+
$elems = jQuery(".chain-test"),
1128+
finish = function() {
1129+
if ( !(--remaining) ) {
1130+
start();
1131+
}
1132+
};
11461133

1147-
jQuery.each([ "in", "out" ], function( i, type ) {
1148-
var $elem = jQuery( "#" + method.toLowerCase() + type ),
1149-
startVal = defProp( $elem );
1134+
jQuery.each( { slideToggle: "height", fadeToggle: "opacity", toggle: "width" }, function( method, prop ) {
1135+
var $methodElems = $elems.filter( "[id^='" + method.toLowerCase() + "']" ).each(function() {
1136+
// Don't end test until we're done with this element
1137+
remaining++;
11501138

1151-
$elem[ method ]( animTime );
1152-
stop();
1139+
// Save original property value for comparison
1140+
jQuery.data( this, "startVal", jQuery( this ).css( prop ) );
11531141

1154-
setTimeout( function() {
1155-
$elem.stop();
1142+
// Expect olddisplay data from our .hide() call below
1143+
QUnit.expectJqData( this, "olddisplay" );
1144+
});
11561145

1157-
notEqual( defProp( $elem ), startVal, ".stop() is called about halfway through animation." );
1146+
// Interrupt a hiding toggle
1147+
$methodElems[ method ]( longDuration );
1148+
setTimeout(function() {
1149+
$methodElems.stop().each(function() {
1150+
notEqual( jQuery( this ).css( prop ), jQuery.data( this, "startVal" ), ".stop() before completion of hiding ." + method + "() - #" + this.id );
1151+
});
11581152

1159-
$elem[ method ](animTime, function() {
1160-
equal( defProp( $elem ), startVal, "After doing .stop() halfway through hide, check that state has been saved for returning to original property value." );
1153+
// Restore
1154+
$methodElems[ method ]( shortDuration, function() {
1155+
var id = this.id,
1156+
$elem = jQuery( this ),
1157+
startVal = $elem.data("startVal");
11611158

1162-
// Start from hidden position to show this time
1163-
$elem.hide()[ method ]( animTime );
1164-
setTimeout( function() {
1165-
$elem.stop();
1159+
$elem.removeData("startVal");
11661160

1167-
notEqual( defProp( $elem ), startVal, ".stop() is called about halfway through animation." );
1161+
equal( $elem.css( prop ), startVal, "original value restored by ." + method + "() - #" + id );
11681162

1169-
$elem[ method ](animTime, function() {
1170-
equal( defProp( $elem ), startVal, "After doing .stop() halfway through show, check that state has been saved for returning to original property value." );
1163+
// Interrupt a showing toggle
1164+
$elem.hide()[ method ]( longDuration );
1165+
setTimeout(function() {
1166+
$elem.stop();
1167+
notEqual( $elem.css( prop ), startVal, ".stop() before completion of showing ." + method + "() - #" + id );
11711168

1172-
// Tolerate olddisplay data from .hide() call
1173-
QUnit.expectJqData( this, "olddisplay" );
1174-
start();
1175-
});
1176-
}, animTime / 2);
1177-
});
1178-
}, animTime / 2);
1179-
});
1169+
// Restore
1170+
$elem[ method ]( shortDuration, function() {
1171+
equal( $elem.css( prop ), startVal, "original value restored by ." + method + "() - #" + id );
1172+
finish();
1173+
});
1174+
}, shortDuration );
1175+
});
1176+
}, shortDuration );
11801177
});
11811178
});
11821179

@@ -1319,7 +1316,7 @@ test( "animate properties missing px w/ opacity as last (#9074)", 2, function()
13191316
notEqual( l, 200, "Left is not 200 after partial animate" );
13201317
div.stop().remove();
13211318
start();
1322-
}, 1000);
1319+
}, 500);
13231320
});
13241321

13251322
test("callbacks should fire in correct order (#9100)", function() {
@@ -1663,7 +1660,7 @@ asyncTest( "multiple unqueued and promise", 4, function() {
16631660
}).animate({
16641661
top: 100
16651662
}, {
1666-
duration: 1500,
1663+
duration: 1000,
16671664
queue: false,
16681665
complete: function() {
16691666
strictEqual( step++, 3, "Step 3" );

0 commit comments

Comments
 (0)
X Tutup