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
This commit is contained in:
Oleg Gaidarenko 2015-08-16 06:45:28 +03:00
parent 9d820fbde6
commit b930d14ce6
24 changed files with 6197 additions and 5940 deletions

View File

@ -137,16 +137,20 @@ function url( value ) {
// Ajax testing helper // Ajax testing helper
this.ajaxTest = function( title, expect, options ) { this.ajaxTest = function( title, expect, options ) {
QUnit.test( title, expect, function( assert ) {
var requestOptions; var requestOptions;
if ( jQuery.isFunction( options ) ) { if ( jQuery.isFunction( options ) ) {
options = options(); options = options( assert );
} }
options = options || []; options = options || [];
requestOptions = options.requests || options.request || options; requestOptions = options.requests || options.request || options;
if ( !jQuery.isArray( requestOptions ) ) { if ( !jQuery.isArray( requestOptions ) ) {
requestOptions = [ requestOptions ]; requestOptions = [ requestOptions ];
} }
asyncTest( title, expect, function() {
var done = assert.async();
if ( options.setup ) { if ( options.setup ) {
options.setup(); options.setup();
} }
@ -160,7 +164,9 @@ this.ajaxTest = function( title, expect, options ) {
if ( options.teardown ) { if ( options.teardown ) {
options.teardown(); options.teardown();
} }
start();
// Make sure all events will be called before done()
setTimeout(done);
} }
}, },
requests = jQuery.map( requestOptions, function( options ) { requests = jQuery.map( requestOptions, function( options ) {
@ -170,7 +176,7 @@ this.ajaxTest = function( title, expect, options ) {
return function( _, status ) { return function( _, status ) {
if ( !completed ) { if ( !completed ) {
if ( !handler ) { if ( !handler ) {
ok( false, "unexpected " + status ); assert.ok( false, "unexpected " + status );
} else if ( jQuery.isFunction( handler ) ) { } else if ( jQuery.isFunction( handler ) ) {
handler.apply( this, arguments ); handler.apply( this, arguments );
} }
@ -179,7 +185,7 @@ this.ajaxTest = function( title, expect, options ) {
}; };
if ( options.afterSend ) { if ( options.afterSend ) {
options.afterSend( request ); options.afterSend( request, assert );
} }
return request return request
@ -202,7 +208,8 @@ this.ajaxTest = function( title, expect, options ) {
}; };
this.testIframe = function( fileName, name, fn ) { this.testIframe = function( fileName, name, fn ) {
asyncTest(name, function() { QUnit.test(name, function( assert ) {
var done = assert.async();
// load fixture in iframe // load fixture in iframe
var iframe = loadFixture(), var iframe = loadFixture(),
@ -211,10 +218,9 @@ this.testIframe = function( fileName, name, fn ) {
if ( win && win.jQuery && win.jQuery.isReady ) { if ( win && win.jQuery && win.jQuery.isReady ) {
clearInterval( interval ); clearInterval( interval );
start();
// call actual tests passing the correct jQuery instance to use // call actual tests passing the correct jQuery instance to use
fn.call( this, win.jQuery, win, win.document ); fn.call( this, win.jQuery, win, win.document, assert );
done();
document.body.removeChild( iframe ); document.body.removeChild( iframe );
iframe = null; iframe = null;
} }
@ -233,11 +239,14 @@ this.testIframe = function( fileName, name, fn ) {
}; };
this.testIframeWithCallback = function( title, fileName, func ) { this.testIframeWithCallback = function( title, fileName, func ) {
asyncTest( title, 1, function() { QUnit.test( title, 1, function( assert ) {
var iframe; var iframe;
var done = assert.async();
window.iframeCallback = function() { window.iframeCallback = function() {
var args = arguments; var args = Array.prototype.slice.call( arguments );
args.push( assert );
setTimeout(function() { setTimeout(function() {
this.iframeCallback = undefined; this.iframeCallback = undefined;
@ -246,7 +255,7 @@ this.testIframeWithCallback = function( title, fileName, func ) {
func.apply( this, args ); func.apply( this, args );
func = function() {}; func = function() {};
start(); done();
}); });
}; };
iframe = jQuery( "<div/>" ).css({ position: "absolute", width: "500px", left: "-600px" }) iframe = jQuery( "<div/>" ).css({ position: "absolute", width: "500px", left: "-600px" })

File diff suppressed because it is too large Load Diff

View File

@ -11,7 +11,7 @@ var oldRaf = window.requestAnimationFrame,
startTime = 505877050; startTime = 505877050;
// This module tests jQuery.Animation and the corresponding 1.8+ effects APIs // This module tests jQuery.Animation and the corresponding 1.8+ effects APIs
module( "animation", { QUnit.module( "animation", {
setup: function() { setup: function() {
window.requestAnimationFrame = null; window.requestAnimationFrame = null;
this.sandbox = sinon.sandbox.create(); this.sandbox = sinon.sandbox.create();
@ -33,53 +33,66 @@ module( "animation", {
} }
} ); } );
test( "Animation( subject, props, opts ) - shape", function() { QUnit.test( "Animation( subject, props, opts ) - shape", function( assert ) {
expect( 20 ); assert.expect( 20 );
var subject = { test: 0 }, var subject = { test: 0 },
props = { test: 1 }, props = { test: 1 },
opts = { queue: "fx", duration: 100 }, opts = { queue: "fx", duration: 100 },
animation = jQuery.Animation( subject, props, opts ); animation = jQuery.Animation( subject, props, opts );
equal( animation.elem, subject, ".elem is set to the exact object passed" ); assert.equal(
equal( animation.originalOptions, opts, ".originalOptions is set to options passed" ); animation.elem,
equal( animation.originalProperties, props, ".originalProperties is set to props passed" ); subject,
".elem is set to the exact object passed"
);
assert.equal(
animation.originalOptions,
opts,
".originalOptions is set to options passed"
);
assert.equal(
animation.originalProperties,
props,
".originalProperties is set to props passed"
);
notEqual( animation.props, props, ".props is not the original however" ); assert.notEqual( animation.props, props, ".props is not the original however" );
deepEqual( animation.props, props, ".props is a copy of the original" ); assert.deepEqual( animation.props, props, ".props is a copy of the original" );
deepEqual( animation.opts, { assert.deepEqual( animation.opts, {
duration: 100, duration: 100,
queue: "fx", queue: "fx",
specialEasing: { test: undefined }, specialEasing: { test: undefined },
easing: jQuery.easing._default easing: jQuery.easing._default
}, ".options is filled with default easing and specialEasing" ); }, ".options is filled with default easing and specialEasing" );
equal( animation.startTime, startTime, "startTime was set" ); assert.equal( animation.startTime, startTime, "startTime was set" );
equal( animation.duration, 100, ".duration is set" ); assert.equal( animation.duration, 100, ".duration is set" );
equal( animation.tweens.length, 1, ".tweens has one Tween" ); assert.equal( animation.tweens.length, 1, ".tweens has one Tween" );
equal( typeof animation.tweens[ 0 ].run, "function", "which has a .run function" ); assert.equal( typeof animation.tweens[ 0 ].run, "function", "which has a .run function" );
equal( typeof animation.createTween, "function", ".createTween is a function" ); assert.equal( typeof animation.createTween, "function", ".createTween is a function" );
equal( typeof animation.stop, "function", ".stop is a function" ); assert.equal( typeof animation.stop, "function", ".stop is a function" );
equal( typeof animation.done, "function", ".done is a function" ); assert.equal( typeof animation.done, "function", ".done is a function" );
equal( typeof animation.fail, "function", ".fail is a function" ); assert.equal( typeof animation.fail, "function", ".fail is a function" );
equal( typeof animation.always, "function", ".always is a function" ); assert.equal( typeof animation.always, "function", ".always is a function" );
equal( typeof animation.progress, "function", ".progress is a function" ); assert.equal( typeof animation.progress, "function", ".progress is a function" );
equal( jQuery.timers.length, 1, "Added a timers function" ); assert.equal( jQuery.timers.length, 1, "Added a timers function" );
equal( jQuery.timers[ 0 ].elem, subject, "...with .elem as the subject" ); assert.equal( jQuery.timers[ 0 ].elem, subject, "...with .elem as the subject" );
equal( jQuery.timers[ 0 ].anim, animation, "...with .anim as the animation" ); assert.equal( jQuery.timers[ 0 ].anim, animation, "...with .anim as the animation" );
equal( jQuery.timers[ 0 ].queue, opts.queue, "...with .queue" ); assert.equal( jQuery.timers[ 0 ].queue, opts.queue, "...with .queue" );
// Cleanup after ourselves by ticking to the end // Cleanup after ourselves by ticking to the end
this.clock.tick( 100 ); this.clock.tick( 100 );
} ); } );
test( "Animation.prefilter( fn ) - calls prefilter after defaultPrefilter", function() { QUnit.test( "Animation.prefilter( fn ) - calls prefilter after defaultPrefilter",
expect( 1 ); function( assert ) {
assert.expect( 1 );
var prefilter = this.sandbox.stub(), var prefilter = this.sandbox.stub(),
defaultSpy = this.sandbox.spy( jQuery.Animation.prefilters, 0 ); defaultSpy = this.sandbox.spy( jQuery.Animation.prefilters, 0 );
@ -87,11 +100,13 @@ test( "Animation.prefilter( fn ) - calls prefilter after defaultPrefilter", func
jQuery.Animation.prefilter( prefilter ); jQuery.Animation.prefilter( prefilter );
jQuery.Animation( {}, {}, {} ); jQuery.Animation( {}, {}, {} );
ok( prefilter.calledAfter( defaultSpy ), "our prefilter called after" ); assert.ok( prefilter.calledAfter( defaultSpy ), "our prefilter called after" );
} ); }
);
test( "Animation.prefilter( fn, true ) - calls prefilter before defaultPrefilter", function() { QUnit.test( "Animation.prefilter( fn, true ) - calls prefilter before defaultPrefilter",
expect( 1 ); function( assert ) {
assert.expect( 1 );
var prefilter = this.sandbox.stub(), var prefilter = this.sandbox.stub(),
defaultSpy = this.sandbox.spy( jQuery.Animation.prefilters, 0 ); defaultSpy = this.sandbox.spy( jQuery.Animation.prefilters, 0 );
@ -99,11 +114,12 @@ test( "Animation.prefilter( fn, true ) - calls prefilter before defaultPrefilter
jQuery.Animation.prefilter( prefilter, true ); jQuery.Animation.prefilter( prefilter, true );
jQuery.Animation( {}, {}, {} ); jQuery.Animation( {}, {}, {} );
ok( prefilter.calledBefore( defaultSpy ), "our prefilter called before" ); assert.ok( prefilter.calledBefore( defaultSpy ), "our prefilter called before" );
} ); }
);
test( "Animation.prefilter - prefilter return hooks", function() { QUnit.test( "Animation.prefilter - prefilter return hooks", function( assert ) {
expect( 34 ); assert.expect( 34 );
var animation, realAnimation, element, var animation, realAnimation, element,
sandbox = this.sandbox, sandbox = this.sandbox,
@ -115,10 +131,10 @@ test( "Animation.prefilter - prefilter return hooks", function() {
realAnimation = this; realAnimation = this;
sandbox.spy( realAnimation, "createTween" ); sandbox.spy( realAnimation, "createTween" );
deepEqual( realAnimation.originalProperties, props, "originalProperties" ); assert.deepEqual( realAnimation.originalProperties, props, "originalProperties" );
equal( arguments[ 0 ], this.elem, "first param elem" ); assert.equal( arguments[ 0 ], this.elem, "first param elem" );
equal( arguments[ 1 ], this.props, "second param props" ); assert.equal( arguments[ 1 ], this.props, "second param props" );
equal( arguments[ 2 ], this.opts, "third param opts" ); assert.equal( arguments[ 2 ], this.opts, "third param opts" );
return ourAnimation; return ourAnimation;
} ), } ),
defaultSpy = sandbox.spy( jQuery.Animation.prefilters, 0 ), defaultSpy = sandbox.spy( jQuery.Animation.prefilters, 0 ),
@ -133,14 +149,25 @@ test( "Animation.prefilter - prefilter return hooks", function() {
animation = jQuery.Animation( target, props, opts ); animation = jQuery.Animation( target, props, opts );
equal( prefilter.callCount, 1, "Called prefilter" ); assert.equal( prefilter.callCount, 1, "Called prefilter" );
equal( defaultSpy.callCount, 0, assert.equal(
"Returning something from a prefilter caused remaining prefilters to not run" ); defaultSpy.callCount,
equal( jQuery.fx.timer.callCount, 0, "Returning something never queues a timer" ); 0,
equal( animation, ourAnimation, "Returning something returned it from jQuery.Animation" ); "Returning something from a prefilter caused remaining prefilters to not run"
equal( realAnimation.createTween.callCount, 0, "Returning something never creates tweens" ); );
equal( TweenSpy.callCount, 0, "Returning something never creates tweens" ); assert.equal( jQuery.fx.timer.callCount, 0, "Returning something never queues a timer" );
assert.equal(
animation,
ourAnimation,
"Returning something returned it from jQuery.Animation"
);
assert.equal(
realAnimation.createTween.callCount,
0,
"Returning something never creates tweens"
);
assert.equal( TweenSpy.callCount, 0, "Returning something never creates tweens" );
// Test overriden usage on queues: // Test overriden usage on queues:
prefilter.reset(); prefilter.reset();
@ -153,64 +180,69 @@ test( "Animation.prefilter - prefilter return hooks", function() {
.animate( props, 100 ) .animate( props, 100 )
.queue( queueSpy ); .queue( queueSpy );
equal( prefilter.callCount, 1, "Called prefilter" ); assert.equal( prefilter.callCount, 1, "Called prefilter" );
equal( queueSpy.callCount, 0, "Next function in queue not called" ); assert.equal( queueSpy.callCount, 0, "Next function in queue not called" );
realAnimation.opts.complete.call( realAnimation.elem ); realAnimation.opts.complete.call( realAnimation.elem );
equal( queueSpy.callCount, 1, "Next function in queue called after complete" ); assert.equal( queueSpy.callCount, 1, "Next function in queue called after complete" );
equal( prefilter.callCount, 2, "Called prefilter again - animation #2" ); assert.equal( prefilter.callCount, 2, "Called prefilter again - animation #2" );
equal( ourAnimation.stop.callCount, 0, ".stop() on our animation hasn't been called" ); assert.equal( ourAnimation.stop.callCount, 0, ".stop() on our animation hasn't been called" );
element.stop(); element.stop();
equal( ourAnimation.stop.callCount, 1, ".stop() called ourAnimation.stop()" ); assert.equal( ourAnimation.stop.callCount, 1, ".stop() called ourAnimation.stop()" );
ok( !ourAnimation.stop.args[ 0 ][ 0 ], ".stop( falsy ) (undefined or false are both valid)" ); assert.ok(
!ourAnimation.stop.args[ 0 ][ 0 ],
".stop( falsy ) (undefined or false are both valid)"
);
equal( queueSpy.callCount, 2, "Next queue function called" ); assert.equal( queueSpy.callCount, 2, "Next queue function called" );
ok( queueSpy.calledAfter( ourAnimation.stop ), "After our animation was told to stop" ); assert.ok( queueSpy.calledAfter( ourAnimation.stop ), "After our animation was told to stop" );
// ourAnimation.stop.reset(); // ourAnimation.stop.reset();
equal( prefilter.callCount, 3, "Got the next animation" ); assert.equal( prefilter.callCount, 3, "Got the next animation" );
ourAnimation.stop.reset(); ourAnimation.stop.reset();
// do not clear queue, gotoEnd // do not clear queue, gotoEnd
element.stop( false, true ); element.stop( false, true );
ok( ourAnimation.stop.calledWith( true ), ".stop(true) calls .stop(true)" ); assert.ok( ourAnimation.stop.calledWith( true ), ".stop(true) calls .stop(true)" );
ok( queueSpy.calledAfter( ourAnimation.stop ), assert.ok( queueSpy.calledAfter( ourAnimation.stop ),
"and the next queue function ran after we were told" ); "and the next queue function ran after we were told" );
} ); } );
test( "Animation.tweener( fn ) - unshifts a * tweener", function() { QUnit.test( "Animation.tweener( fn ) - unshifts a * tweener", function( assert ) {
expect( 2 ); assert.expect( 2 );
var starTweeners = jQuery.Animation.tweeners[ "*" ]; var starTweeners = jQuery.Animation.tweeners[ "*" ];
jQuery.Animation.tweener( jQuery.noop ); jQuery.Animation.tweener( jQuery.noop );
equal( starTweeners.length, 2 ); assert.equal( starTweeners.length, 2 );
deepEqual( starTweeners, [ jQuery.noop, defaultTweener ] ); assert.deepEqual( starTweeners, [ jQuery.noop, defaultTweener ] );
} ); } );
test( "Animation.tweener( 'prop', fn ) - unshifts a 'prop' tweener", function() { QUnit.test( "Animation.tweener( 'prop', fn ) - unshifts a 'prop' tweener", function( assert ) {
expect( 4 ); assert.expect( 4 );
var tweeners = jQuery.Animation.tweeners, var tweeners = jQuery.Animation.tweeners,
fn = function() {}; fn = function() {};
jQuery.Animation.tweener( "prop", jQuery.noop ); jQuery.Animation.tweener( "prop", jQuery.noop );
equal( tweeners.prop.length, 1 ); assert.equal( tweeners.prop.length, 1 );
deepEqual( tweeners.prop, [ jQuery.noop ] ); assert.deepEqual( tweeners.prop, [ jQuery.noop ] );
jQuery.Animation.tweener( "prop", fn ); jQuery.Animation.tweener( "prop", fn );
equal( tweeners.prop.length, 2 ); assert.equal( tweeners.prop.length, 2 );
deepEqual( tweeners.prop, [ fn, jQuery.noop ] ); assert.deepEqual( tweeners.prop, [ fn, jQuery.noop ] );
} ); } );
test( "Animation.tweener( 'list of props', fn ) - unshifts a tweener to each prop", function() { QUnit.test(
expect( 2 ); "Animation.tweener( 'list of props', fn ) - unshifts a tweener to each prop",
function( assert ) {
assert.expect( 2 );
var tweeners = jQuery.Animation.tweeners, var tweeners = jQuery.Animation.tweeners,
fn = function() {}; fn = function() {};
jQuery.Animation.tweener( "list of props", jQuery.noop ); jQuery.Animation.tweener( "list of props", jQuery.noop );
deepEqual( tweeners, { assert.deepEqual( tweeners, {
list: [ jQuery.noop ], list: [ jQuery.noop ],
of: [ jQuery.noop ], of: [ jQuery.noop ],
props: [ jQuery.noop ], props: [ jQuery.noop ],
@ -219,12 +251,13 @@ test( "Animation.tweener( 'list of props', fn ) - unshifts a tweener to each pro
// Test with extra whitespaces // Test with extra whitespaces
jQuery.Animation.tweener( " list\t of \tprops\n*", fn ); jQuery.Animation.tweener( " list\t of \tprops\n*", fn );
deepEqual( tweeners, { assert.deepEqual( tweeners, {
list: [ fn, jQuery.noop ], list: [ fn, jQuery.noop ],
of: [ fn, jQuery.noop ], of: [ fn, jQuery.noop ],
props: [ fn, jQuery.noop ], props: [ fn, jQuery.noop ],
"*": [ fn, defaultTweener ] "*": [ fn, defaultTweener ]
} ); } );
} ); }
);
} )(); } )();

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
module( "callbacks", { QUnit.module( "callbacks", {
teardown: moduleTeardown teardown: moduleTeardown
}); });
@ -63,9 +63,9 @@ jQuery.each( tests, function( strFlags, resultString ) {
"object": objectFlags "object": objectFlags
}, function( flagsTypes, flags ) { }, function( flagsTypes, flags ) {
test( "jQuery.Callbacks( " + showFlags( flags ) + " ) - " + filterLabel, function() { QUnit.test( "jQuery.Callbacks( " + showFlags( flags ) + " ) - " + filterLabel, function( assert ) {
expect( 29 ); assert.expect( 29 );
var cblist, var cblist,
results = resultString.split( /\s+/ ); results = resultString.split( /\s+/ );
@ -73,32 +73,32 @@ jQuery.each( tests, function( strFlags, resultString ) {
// Basic binding and firing // Basic binding and firing
output = "X"; output = "X";
cblist = jQuery.Callbacks( flags ); cblist = jQuery.Callbacks( flags );
strictEqual( cblist.locked(), false, ".locked() initially false" ); assert.strictEqual( cblist.locked(), false, ".locked() initially false" );
strictEqual( cblist.disabled(), false, ".disabled() initially false" ); assert.strictEqual( cblist.disabled(), false, ".disabled() initially false" );
strictEqual( cblist.fired(), false, ".fired() initially false" ); assert.strictEqual( cblist.fired(), false, ".fired() initially false" );
cblist.add(function( str ) { cblist.add(function( str ) {
output += str; output += str;
}); });
strictEqual( cblist.fired(), false, ".fired() still false after .add" ); assert.strictEqual( cblist.fired(), false, ".fired() still false after .add" );
cblist.fire( "A" ); cblist.fire( "A" );
strictEqual( output, "XA", "Basic binding and firing" ); assert.strictEqual( output, "XA", "Basic binding and firing" );
strictEqual( cblist.fired(), true, ".fired() detects firing" ); assert.strictEqual( cblist.fired(), true, ".fired() detects firing" );
output = "X"; output = "X";
cblist.disable(); cblist.disable();
cblist.add(function( str ) { cblist.add(function( str ) {
output += str; output += str;
}); });
strictEqual( output, "X", "Adding a callback after disabling" ); assert.strictEqual( output, "X", "Adding a callback after disabling" );
cblist.fire("A"); cblist.fire("A");
strictEqual( output, "X", "Firing after disabling" ); assert.strictEqual( output, "X", "Firing after disabling" );
strictEqual( cblist.disabled(), true, ".disabled() becomes true" ); assert.strictEqual( cblist.disabled(), true, ".disabled() becomes true" );
strictEqual( cblist.locked(), true, "disabling locks" ); assert.strictEqual( cblist.locked(), true, "disabling locks" );
// Emptying while firing (#13517) // Emptying while firing (#13517)
cblist = jQuery.Callbacks( flags ); cblist = jQuery.Callbacks( flags );
cblist.add( cblist.empty ); cblist.add( cblist.empty );
cblist.add( function() { cblist.add( function() {
ok( false, "not emptied" ); assert.ok( false, "not emptied" );
} ); } );
cblist.fire(); cblist.fire();
@ -106,7 +106,7 @@ jQuery.each( tests, function( strFlags, resultString ) {
cblist = jQuery.Callbacks( flags ); cblist = jQuery.Callbacks( flags );
cblist.add( cblist.disable ); cblist.add( cblist.disable );
cblist.add( function() { cblist.add( function() {
ok( false, "not disabled" ); assert.ok( false, "not disabled" );
} ); } );
cblist.fire(); cblist.fire();
@ -114,18 +114,18 @@ jQuery.each( tests, function( strFlags, resultString ) {
output = "X"; output = "X";
cblist = jQuery.Callbacks( flags ); cblist = jQuery.Callbacks( flags );
cblist.add(function() { cblist.add(function() {
equal( this, window, "Basic binding and firing (context)" ); assert.equal( this, window, "Basic binding and firing (context)" );
output += Array.prototype.join.call( arguments, "" ); output += Array.prototype.join.call( arguments, "" );
}); });
cblist.fireWith( window, [ "A", "B" ] ); cblist.fireWith( window, [ "A", "B" ] );
strictEqual( output, "XAB", "Basic binding and firing (arguments)" ); assert.strictEqual( output, "XAB", "Basic binding and firing (arguments)" );
// fireWith with no arguments // fireWith with no arguments
output = ""; output = "";
cblist = jQuery.Callbacks( flags ); cblist = jQuery.Callbacks( flags );
cblist.add(function() { cblist.add(function() {
equal( this, window, "fireWith with no arguments (context is window)" ); assert.equal( this, window, "fireWith with no arguments (context is window)" );
strictEqual( arguments.length, 0, "fireWith with no arguments (no arguments)" ); assert.strictEqual( arguments.length, 0, "fireWith with no arguments (no arguments)" );
}); });
cblist.fireWith(); cblist.fireWith();
@ -135,7 +135,7 @@ jQuery.each( tests, function( strFlags, resultString ) {
cblist.add( outputA, outputB, outputC ); cblist.add( outputA, outputB, outputC );
cblist.remove( outputB, outputC ); cblist.remove( outputB, outputC );
cblist.fire(); cblist.fire();
strictEqual( output, "XA", "Basic binding, removing and firing" ); assert.strictEqual( output, "XA", "Basic binding, removing and firing" );
// Empty // Empty
output = "X"; output = "X";
@ -145,7 +145,7 @@ jQuery.each( tests, function( strFlags, resultString ) {
cblist.add( outputC ); cblist.add( outputC );
cblist.empty(); cblist.empty();
cblist.fire(); cblist.fire();
strictEqual( output, "X", "Empty" ); assert.strictEqual( output, "X", "Empty" );
// Locking // Locking
output = "X"; output = "X";
@ -161,8 +161,8 @@ jQuery.each( tests, function( strFlags, resultString ) {
cblist.add(function( str ) { cblist.add(function( str ) {
output += str; output += str;
}); });
strictEqual( output, "X", "Lock early" ); assert.strictEqual( output, "X", "Lock early" );
strictEqual( cblist.locked(), true, "Locking reflected in accessor" ); assert.strictEqual( cblist.locked(), true, "Locking reflected in accessor" );
// Locking while firing (gh-1990) // Locking while firing (gh-1990)
output = "X"; output = "X";
@ -172,7 +172,7 @@ jQuery.each( tests, function( strFlags, resultString ) {
output += str; output += str;
}); });
cblist.fire( "A" ); cblist.fire( "A" );
strictEqual( output, "XA", "Locking doesn't abort execution (gh-1990)" ); assert.strictEqual( output, "XA", "Locking doesn't abort execution (gh-1990)" );
// Ordering // Ordering
output = "X"; output = "X";
@ -182,7 +182,7 @@ jQuery.each( tests, function( strFlags, resultString ) {
outputA(); outputA();
}, outputB ); }, outputB );
cblist.fire(); cblist.fire();
strictEqual( output, results.shift(), "Proper ordering" ); assert.strictEqual( output, results.shift(), "Proper ordering" );
// Add and fire again // Add and fire again
output = "X"; output = "X";
@ -190,11 +190,11 @@ jQuery.each( tests, function( strFlags, resultString ) {
cblist.add( outputC ); cblist.add( outputC );
outputA(); outputA();
}, outputB ); }, outputB );
strictEqual( output, results.shift(), "Add after fire" ); assert.strictEqual( output, results.shift(), "Add after fire" );
output = "X"; output = "X";
cblist.fire(); cblist.fire();
strictEqual( output, results.shift(), "Fire again" ); assert.strictEqual( output, results.shift(), "Fire again" );
// Multiple fire // Multiple fire
output = "X"; output = "X";
@ -203,20 +203,20 @@ jQuery.each( tests, function( strFlags, resultString ) {
output += str; output += str;
}); });
cblist.fire("A"); cblist.fire("A");
strictEqual( output, "XA", "Multiple fire (first fire)" ); assert.strictEqual( output, "XA", "Multiple fire (first fire)" );
output = "X"; output = "X";
cblist.add(function( str ) { cblist.add(function( str ) {
output += str; output += str;
}); });
strictEqual( output, results.shift(), "Multiple fire (first new callback)" ); assert.strictEqual( output, results.shift(), "Multiple fire (first new callback)" );
output = "X"; output = "X";
cblist.fire("B"); cblist.fire("B");
strictEqual( output, results.shift(), "Multiple fire (second fire)" ); assert.strictEqual( output, results.shift(), "Multiple fire (second fire)" );
output = "X"; output = "X";
cblist.add(function( str ) { cblist.add(function( str ) {
output += str; output += str;
}); });
strictEqual( output, results.shift(), "Multiple fire (second new callback)" ); assert.strictEqual( output, results.shift(), "Multiple fire (second new callback)" );
// Return false // Return false
output = "X"; output = "X";
@ -224,12 +224,12 @@ jQuery.each( tests, function( strFlags, resultString ) {
cblist.add( outputA, function() { return false; }, outputB ); cblist.add( outputA, function() { return false; }, outputB );
cblist.add( outputA ); cblist.add( outputA );
cblist.fire(); cblist.fire();
strictEqual( output, results.shift(), "Callback returning false" ); assert.strictEqual( output, results.shift(), "Callback returning false" );
// Add another callback (to control lists with memory do not fire anymore) // Add another callback (to control lists with memory do not fire anymore)
output = "X"; output = "X";
cblist.add( outputC ); cblist.add( outputC );
strictEqual( output, results.shift(), "Adding a callback after one returned false" ); assert.strictEqual( output, results.shift(), "Adding a callback after one returned false" );
// Callbacks are not iterated // Callbacks are not iterated
output = ""; output = "";
@ -243,7 +243,7 @@ jQuery.each( tests, function( strFlags, resultString ) {
cblist.add( handler ); cblist.add( handler );
cblist.add( handler ); cblist.add( handler );
cblist.fire(); cblist.fire();
strictEqual( output, results.shift(), "No callback iteration" ); assert.strictEqual( output, results.shift(), "No callback iteration" );
}); });
}); });
}); });
@ -251,9 +251,9 @@ jQuery.each( tests, function( strFlags, resultString ) {
})(); })();
test( "jQuery.Callbacks( options ) - options are copied", function() { QUnit.test( "jQuery.Callbacks( options ) - options are copied", function( assert ) {
expect( 1 ); assert.expect( 1 );
var options = { var options = {
"unique": true "unique": true
@ -261,16 +261,16 @@ test( "jQuery.Callbacks( options ) - options are copied", function() {
cb = jQuery.Callbacks( options ), cb = jQuery.Callbacks( options ),
count = 0, count = 0,
fn = function() { fn = function() {
ok( !( count++ ), "called once" ); assert.ok( !( count++ ), "called once" );
}; };
options["unique"] = false; options["unique"] = false;
cb.add( fn, fn ); cb.add( fn, fn );
cb.fire(); cb.fire();
}); });
test( "jQuery.Callbacks.fireWith - arguments are copied", function() { QUnit.test( "jQuery.Callbacks.fireWith - arguments are copied", function( assert ) {
expect( 1 ); assert.expect( 1 );
var cb = jQuery.Callbacks("memory"), var cb = jQuery.Callbacks("memory"),
args = ["hello"]; args = ["hello"];
@ -279,28 +279,28 @@ test( "jQuery.Callbacks.fireWith - arguments are copied", function() {
args[ 0 ] = "world"; args[ 0 ] = "world";
cb.add(function( hello ) { cb.add(function( hello ) {
strictEqual( hello, "hello", "arguments are copied internally" ); assert.strictEqual( hello, "hello", "arguments are copied internally" );
}); });
}); });
test( "jQuery.Callbacks.remove - should remove all instances", function() { QUnit.test( "jQuery.Callbacks.remove - should remove all instances", function( assert ) {
expect( 1 ); assert.expect( 1 );
var cb = jQuery.Callbacks(); var cb = jQuery.Callbacks();
function fn() { function fn() {
ok( false, "function wasn't removed" ); assert.ok( false, "function wasn't removed" );
} }
cb.add( fn, fn, function() { cb.add( fn, fn, function() {
ok( true, "end of test" ); assert.ok( true, "end of test" );
}).remove( fn ).fire(); }).remove( fn ).fire();
}); });
test( "jQuery.Callbacks.has", function() { QUnit.test( "jQuery.Callbacks.has", function( assert ) {
expect( 13 ); assert.expect( 13 );
var cb = jQuery.Callbacks(); var cb = jQuery.Callbacks();
function getA() { function getA() {
@ -313,48 +313,48 @@ test( "jQuery.Callbacks.has", function() {
return "C"; return "C";
} }
cb.add(getA, getB, getC); cb.add(getA, getB, getC);
strictEqual( cb.has(), true, "No arguments to .has() returns whether callback function(s) are attached or not" ); assert.strictEqual( cb.has(), true, "No arguments to .has() returns whether callback function(s) are attached or not" );
strictEqual( cb.has(getA), true, "Check if a specific callback function is in the Callbacks list" ); assert.strictEqual( cb.has(getA), true, "Check if a specific callback function is in the Callbacks list" );
cb.remove(getB); cb.remove(getB);
strictEqual( cb.has(getB), false, "Remove a specific callback function and make sure its no longer there" ); assert.strictEqual( cb.has(getB), false, "Remove a specific callback function and make sure its no longer there" );
strictEqual( cb.has(getA), true, "Remove a specific callback function and make sure other callback function is still there" ); assert.strictEqual( cb.has(getA), true, "Remove a specific callback function and make sure other callback function is still there" );
cb.empty(); cb.empty();
strictEqual( cb.has(), false, "Empty list and make sure there are no callback function(s)" ); assert.strictEqual( cb.has(), false, "Empty list and make sure there are no callback function(s)" );
strictEqual( cb.has(getA), false, "Check for a specific function in an empty() list" ); assert.strictEqual( cb.has(getA), false, "Check for a specific function in an empty() list" );
cb.add(getA, getB, function(){ cb.add(getA, getB, function(){
strictEqual( cb.has(), true, "Check if list has callback function(s) from within a callback function" ); assert.strictEqual( cb.has(), true, "Check if list has callback function(s) from within a callback function" );
strictEqual( cb.has(getA), true, "Check if list has a specific callback from within a callback function" ); assert.strictEqual( cb.has(getA), true, "Check if list has a specific callback from within a callback function" );
}).fire(); }).fire();
strictEqual( cb.has(), true, "Callbacks list has callback function(s) after firing" ); assert.strictEqual( cb.has(), true, "Callbacks list has callback function(s) after firing" );
cb.disable(); cb.disable();
strictEqual( cb.has(), false, "disabled() list has no callback functions (returns false)" ); assert.strictEqual( cb.has(), false, "disabled() list has no callback functions (returns false)" );
strictEqual( cb.has(getA), false, "Check for a specific function in a disabled() list" ); assert.strictEqual( cb.has(getA), false, "Check for a specific function in a disabled() list" );
cb = jQuery.Callbacks("unique"); cb = jQuery.Callbacks("unique");
cb.add(getA); cb.add(getA);
cb.add(getA); cb.add(getA);
strictEqual( cb.has(), true, "Check if unique list has callback function(s) attached" ); assert.strictEqual( cb.has(), true, "Check if unique list has callback function(s) attached" );
cb.lock(); cb.lock();
strictEqual( cb.has(), false, "locked() list is empty and returns false" ); assert.strictEqual( cb.has(), false, "locked() list is empty and returns false" );
}); });
test( "jQuery.Callbacks() - adding a string doesn't cause a stack overflow", function() { QUnit.test( "jQuery.Callbacks() - adding a string doesn't cause a stack overflow", function( assert ) {
expect( 1 ); assert.expect( 1 );
jQuery.Callbacks().add( "hello world" ); jQuery.Callbacks().add( "hello world" );
ok( true, "no stack overflow" ); assert.ok( true, "no stack overflow" );
}); });
test( "jQuery.Callbacks() - disabled callback doesn't fire (gh-1790)", function() { QUnit.test( "jQuery.Callbacks() - disabled callback doesn't fire (gh-1790)", function( assert ) {
expect( 1 ); assert.expect( 1 );
var cb = jQuery.Callbacks(), var cb = jQuery.Callbacks(),
fired = false, fired = false,
@ -364,5 +364,5 @@ test( "jQuery.Callbacks() - disabled callback doesn't fire (gh-1790)", function(
cb.empty(); cb.empty();
cb.add( shot ); cb.add( shot );
cb.fire(); cb.fire();
ok( !fired, "Disabled callback function didn't fire" ); assert.ok( !fired, "Disabled callback function didn't fire" );
}); });

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
module( "deferred", { QUnit.module( "deferred", {
teardown: moduleTeardown teardown: moduleTeardown
}); });
@ -8,51 +8,51 @@ jQuery.each( [ "", " - new operator" ], function( _, withNew ) {
return withNew ? new jQuery.Deferred( fn ) : jQuery.Deferred( fn ); return withNew ? new jQuery.Deferred( fn ) : jQuery.Deferred( fn );
} }
test( "jQuery.Deferred" + withNew, function() { QUnit.test( "jQuery.Deferred" + withNew, function( assert ) {
expect( 23 ); assert.expect( 23 );
var defer = createDeferred(); var defer = createDeferred();
ok( jQuery.isFunction( defer.pipe ), "defer.pipe is a function" ); assert.ok( jQuery.isFunction( defer.pipe ), "defer.pipe is a function" );
createDeferred().resolve().done(function() { createDeferred().resolve().done(function() {
ok( true, "Success on resolve" ); assert.ok( true, "Success on resolve" );
strictEqual( this.state(), "resolved", "Deferred is resolved (state)" ); assert.strictEqual( this.state(), "resolved", "Deferred is resolved (state)" );
}).fail(function() { }).fail(function() {
ok( false, "Error on resolve" ); assert.ok( false, "Error on resolve" );
}).always(function() { }).always(function() {
ok( true, "Always callback on resolve" ); assert.ok( true, "Always callback on resolve" );
}); });
createDeferred().reject().done(function() { createDeferred().reject().done(function() {
ok( false, "Success on reject" ); assert.ok( false, "Success on reject" );
}).fail(function() { }).fail(function() {
ok( true, "Error on reject" ); assert.ok( true, "Error on reject" );
strictEqual( this.state(), "rejected", "Deferred is rejected (state)" ); assert.strictEqual( this.state(), "rejected", "Deferred is rejected (state)" );
}).always(function() { }).always(function() {
ok( true, "Always callback on reject" ); assert.ok( true, "Always callback on reject" );
}); });
createDeferred(function( defer ) { createDeferred(function( defer ) {
ok( this === defer, "Defer passed as this & first argument" ); assert.ok( this === defer, "Defer passed as this & first argument" );
this.resolve("done"); this.resolve("done");
}).done(function( value ) { }).done(function( value ) {
strictEqual( value, "done", "Passed function executed" ); assert.strictEqual( value, "done", "Passed function executed" );
}); });
createDeferred(function( defer ) { createDeferred(function( defer ) {
var promise = defer.promise(), var promise = defer.promise(),
func = function() {}, func = function() {},
funcPromise = defer.promise( func ); funcPromise = defer.promise( func );
strictEqual( defer.promise(), promise, "promise is always the same" ); assert.strictEqual( defer.promise(), promise, "promise is always the same" );
strictEqual( funcPromise, func, "non objects get extended" ); assert.strictEqual( funcPromise, func, "non objects get extended" );
jQuery.each( promise, function( key ) { jQuery.each( promise, function( key ) {
if ( !jQuery.isFunction( promise[ key ] ) ) { if ( !jQuery.isFunction( promise[ key ] ) ) {
ok( false, key + " is a function (" + jQuery.type( promise[ key ] ) + ")" ); assert.ok( false, key + " is a function (" + jQuery.type( promise[ key ] ) + ")" );
} }
if ( promise[ key ] !== func[ key ] ) { if ( promise[ key ] !== func[ key ] ) {
strictEqual( func[ key ], promise[ key ], key + " is the same" ); assert.strictEqual( func[ key ], promise[ key ], key + " is the same" );
} }
}); });
}); });
@ -60,17 +60,17 @@ jQuery.each( [ "", " - new operator" ], function( _, withNew ) {
jQuery.expandedEach = jQuery.each; jQuery.expandedEach = jQuery.each;
jQuery.expandedEach( "resolve reject".split(" "), function( _, change ) { jQuery.expandedEach( "resolve reject".split(" "), function( _, change ) {
createDeferred(function( defer ) { createDeferred(function( defer ) {
strictEqual( defer.state(), "pending", "pending after creation" ); assert.strictEqual( defer.state(), "pending", "pending after creation" );
var checked = 0; var checked = 0;
defer.progress(function( value ) { defer.progress(function( value ) {
strictEqual( value, checked, "Progress: right value (" + value + ") received" ); assert.strictEqual( value, checked, "Progress: right value (" + value + ") received" );
}); });
for ( checked = 0; checked < 3; checked++ ) { for ( checked = 0; checked < 3; checked++ ) {
defer.notify( checked ); defer.notify( checked );
} }
strictEqual( defer.state(), "pending", "pending after notification" ); assert.strictEqual( defer.state(), "pending", "pending after notification" );
defer[ change ](); defer[ change ]();
notStrictEqual( defer.state(), "pending", "not pending after " + change ); assert.notStrictEqual( defer.state(), "pending", "not pending after " + change );
defer.notify(); defer.notify();
}); });
}); });
@ -78,22 +78,22 @@ jQuery.each( [ "", " - new operator" ], function( _, withNew ) {
}); });
test( "jQuery.Deferred - chainability", function() { QUnit.test( "jQuery.Deferred - chainability", function( assert ) {
var defer = jQuery.Deferred(); var defer = jQuery.Deferred();
expect( 10 ); assert.expect( 10 );
jQuery.expandedEach = jQuery.each; jQuery.expandedEach = jQuery.each;
jQuery.expandedEach( "resolve reject notify resolveWith rejectWith notifyWith done fail progress always".split(" "), function( _, method ) { jQuery.expandedEach( "resolve reject notify resolveWith rejectWith notifyWith done fail progress always".split(" "), function( _, method ) {
var object = { var object = {
m: defer[ method ] m: defer[ method ]
}; };
strictEqual( object.m(), object, method + " is chainable" ); assert.strictEqual( object.m(), object, method + " is chainable" );
}); });
}); });
test( "jQuery.Deferred.then - filtering (done)", function( assert ) { QUnit.test( "jQuery.Deferred.then - filtering (done)", function( assert ) {
assert.expect( 4 ); assert.expect( 4 );
@ -130,7 +130,7 @@ test( "jQuery.Deferred.then - filtering (done)", function( assert ) {
}); });
}); });
test( "jQuery.Deferred.then - filtering (fail)", function( assert ) { QUnit.test( "jQuery.Deferred.then - filtering (fail)", function( assert ) {
assert.expect( 4 ); assert.expect( 4 );
@ -167,7 +167,7 @@ test( "jQuery.Deferred.then - filtering (fail)", function( assert ) {
}); });
}); });
test( "jQuery.Deferred.catch", function( assert ) { QUnit.test( "jQuery.Deferred.catch", function( assert ) {
assert.expect( 4 ); assert.expect( 4 );
var value1, value2, value3, var value1, value2, value3,
@ -203,7 +203,7 @@ test( "jQuery.Deferred.catch", function( assert ) {
}); });
}); });
test( "[PIPE ONLY] jQuery.Deferred.pipe - filtering (fail)", function( assert ) { QUnit.test( "[PIPE ONLY] jQuery.Deferred.pipe - filtering (fail)", function( assert ) {
assert.expect( 4 ); assert.expect( 4 );
@ -240,7 +240,7 @@ test( "[PIPE ONLY] jQuery.Deferred.pipe - filtering (fail)", function( assert )
}); });
}); });
test( "jQuery.Deferred.then - filtering (progress)", function( assert ) { QUnit.test( "jQuery.Deferred.then - filtering (progress)", function( assert ) {
assert.expect( 3 ); assert.expect( 3 );
@ -268,7 +268,7 @@ test( "jQuery.Deferred.then - filtering (progress)", function( assert ) {
}); });
}); });
test( "jQuery.Deferred.then - deferred (done)", function( assert ) { QUnit.test( "jQuery.Deferred.then - deferred (done)", function( assert ) {
assert.expect( 3 ); assert.expect( 3 );
@ -300,7 +300,7 @@ test( "jQuery.Deferred.then - deferred (done)", function( assert ) {
}); });
}); });
test( "jQuery.Deferred.then - deferred (fail)", function( assert ) { QUnit.test( "jQuery.Deferred.then - deferred (fail)", function( assert ) {
assert.expect( 3 ); assert.expect( 3 );
@ -332,7 +332,7 @@ test( "jQuery.Deferred.then - deferred (fail)", function( assert ) {
}); });
}); });
test( "jQuery.Deferred.then - deferred (progress)", function( assert ) { QUnit.test( "jQuery.Deferred.then - deferred (progress)", function( assert ) {
assert.expect( 3 ); assert.expect( 3 );
@ -372,7 +372,7 @@ test( "jQuery.Deferred.then - deferred (progress)", function( assert ) {
}); });
}); });
test( "[PIPE ONLY] jQuery.Deferred.pipe - deferred (progress)", function( assert ) { QUnit.test( "[PIPE ONLY] jQuery.Deferred.pipe - deferred (progress)", function( assert ) {
assert.expect( 3 ); assert.expect( 3 );
@ -404,7 +404,7 @@ test( "[PIPE ONLY] jQuery.Deferred.pipe - deferred (progress)", function( assert
}); });
}); });
test( "jQuery.Deferred.then - context", function( assert ) { QUnit.test( "jQuery.Deferred.then - context", function( assert ) {
assert.expect( 7 ); assert.expect( 7 );
@ -455,7 +455,7 @@ test( "jQuery.Deferred.then - context", function( assert ) {
}); });
}); });
test( "[PIPE ONLY] jQuery.Deferred.pipe - context", function( assert ) { QUnit.test( "[PIPE ONLY] jQuery.Deferred.pipe - context", function( assert ) {
assert.expect( 7 ); assert.expect( 7 );
@ -506,9 +506,9 @@ test( "[PIPE ONLY] jQuery.Deferred.pipe - context", function( assert ) {
}); });
}); });
asyncTest( "jQuery.Deferred.then - spec compatibility", function() { QUnit.asyncTest( "jQuery.Deferred.then - spec compatibility", function( assert ) {
expect( 1 ); assert.expect( 1 );
var defer = jQuery.Deferred().done(function() { var defer = jQuery.Deferred().done(function() {
setTimeout( start ); setTimeout( start );
@ -516,7 +516,7 @@ asyncTest( "jQuery.Deferred.then - spec compatibility", function() {
}); });
defer.then(function() { defer.then(function() {
ok( true, "errors in .done callbacks don't stop .then handlers" ); assert.ok( true, "errors in .done callbacks don't stop .then handlers" );
}); });
try { try {
@ -524,9 +524,9 @@ asyncTest( "jQuery.Deferred.then - spec compatibility", function() {
} catch ( _ ) {} } catch ( _ ) {}
}); });
test( "jQuery.Deferred - 1.x/2.x compatibility", function( assert ) { QUnit.test( "jQuery.Deferred - 1.x/2.x compatibility", function( assert ) {
expect( 8 ); assert.expect( 8 );
var context = { id: "callback context" }, var context = { id: "callback context" },
thenable = jQuery.Deferred().resolve( "thenable fulfillment" ).promise(), thenable = jQuery.Deferred().resolve( "thenable fulfillment" ).promise(),
@ -575,16 +575,16 @@ test( "jQuery.Deferred - 1.x/2.x compatibility", function( assert ) {
}); });
}); });
test( "jQuery.Deferred.then - progress and thenables", function( assert ) { QUnit.test( "jQuery.Deferred.then - progress and thenables", function( assert ) {
expect( 2 ); assert.expect( 2 );
var trigger = jQuery.Deferred().notify(), var trigger = jQuery.Deferred().notify(),
expectedProgress = [ "baz", "baz" ], expectedProgress = [ "baz", "baz" ],
done = jQuery.map( new Array( 2 ), function() { return assert.async(); } ), done = jQuery.map( new Array( 2 ), function() { return assert.async(); } ),
failer = function( evt ) { failer = function( evt ) {
return function() { return function() {
ok( false, "no unexpected " + evt ); assert.ok( false, "no unexpected " + evt );
}; };
}; };
@ -601,9 +601,9 @@ test( "jQuery.Deferred.then - progress and thenables", function( assert ) {
trigger.notify(); trigger.notify();
}); });
test( "jQuery.Deferred - notify and resolve", function( assert ) { QUnit.test( "jQuery.Deferred - notify and resolve", function( assert ) {
expect( 7 ); assert.expect( 7 );
var notifiedResolved = jQuery.Deferred().notify( "foo" )/*xxx .resolve( "bar" )*/, var notifiedResolved = jQuery.Deferred().notify( "foo" )/*xxx .resolve( "bar" )*/,
done = jQuery.map( new Array( 3 ), function() { return assert.async(); } ); done = jQuery.map( new Array( 3 ), function() { return assert.async(); } );
@ -649,9 +649,9 @@ test( "jQuery.Deferred - notify and resolve", function( assert ) {
} ); } );
}); });
test( "jQuery.when", function() { QUnit.test( "jQuery.when", function( assert ) {
expect( 37 ); assert.expect( 37 );
// Some other objects // Some other objects
jQuery.each({ jQuery.each({
@ -667,22 +667,22 @@ test( "jQuery.when", function() {
"an array": [ 1, 2, 3 ] "an array": [ 1, 2, 3 ]
}, function( message, value ) { }, function( message, value ) {
ok( assert.ok(
jQuery.isFunction( jQuery.isFunction(
jQuery.when( value ).done(function( resolveValue ) { jQuery.when( value ).done(function( resolveValue ) {
strictEqual( this, window, "Context is the global object with " + message ); assert.strictEqual( this, window, "Context is the global object with " + message );
strictEqual( resolveValue, value, "Test the promise was resolved with " + message ); assert.strictEqual( resolveValue, value, "Test the promise was resolved with " + message );
}).promise }).promise
), ),
"Test " + message + " triggers the creation of a new Promise" "Test " + message + " triggers the creation of a new Promise"
); );
}); });
ok( assert.ok(
jQuery.isFunction( jQuery.isFunction(
jQuery.when().done(function( resolveValue ) { jQuery.when().done(function( resolveValue ) {
strictEqual( this, window, "Test the promise was resolved with window as its context" ); assert.strictEqual( this, window, "Test the promise was resolved with window as its context" );
strictEqual( resolveValue, undefined, "Test the promise was resolved with no parameter" ); assert.strictEqual( resolveValue, undefined, "Test the promise was resolved with no parameter" );
}).promise }).promise
), ),
"Test calling when with no parameter triggers the creation of a new Promise" "Test calling when with no parameter triggers the creation of a new Promise"
@ -692,7 +692,7 @@ test( "jQuery.when", function() {
context = {}; context = {};
jQuery.when( jQuery.Deferred().resolveWith( context ) ).done(function() { jQuery.when( jQuery.Deferred().resolveWith( context ) ).done(function() {
strictEqual( this, context, "when( promise ) propagates context" ); assert.strictEqual( this, context, "when( promise ) propagates context" );
}); });
jQuery.each([ 1, 2, 3 ], function( k, i ) { jQuery.each([ 1, 2, 3 ], function( k, i ) {
@ -702,16 +702,16 @@ test( "jQuery.when", function() {
}) })
).done(function( value ) { ).done(function( value ) {
strictEqual( value, 1, "Function executed" + ( i > 1 ? " only once" : "" ) ); assert.strictEqual( value, 1, "Function executed" + ( i > 1 ? " only once" : "" ) );
cache = value; cache = value;
}); });
}); });
}); });
test( "jQuery.when - joined", function() { QUnit.test( "jQuery.when - joined", function( assert ) {
expect( 195 ); assert.expect( 195 );
var deferreds = { var deferreds = {
rawValue: 1, rawValue: 1,
@ -741,11 +741,11 @@ test( "jQuery.when - joined", function() {
}, },
counter = 49; counter = 49;
stop(); QUnit.stop();
function restart() { function restart() {
if ( !--counter ) { if ( !--counter ) {
start(); QUnit.start();
} }
} }
@ -764,22 +764,22 @@ test( "jQuery.when - joined", function() {
jQuery.when( defer1, defer2 ).done(function( a, b ) { jQuery.when( defer1, defer2 ).done(function( a, b ) {
if ( shouldResolve ) { if ( shouldResolve ) {
deepEqual( [ a, b ], expected, code + " => resolve" ); assert.deepEqual( [ a, b ], expected, code + " => resolve" );
strictEqual( this[ 0 ], context1, code + " => first context OK" ); assert.strictEqual( this[ 0 ], context1, code + " => first context OK" );
strictEqual( this[ 1 ], context2, code + " => second context OK" ); assert.strictEqual( this[ 1 ], context2, code + " => second context OK" );
} else { } else {
ok( false, code + " => resolve" ); assert.ok( false, code + " => resolve" );
} }
}).fail(function( a, b ) { }).fail(function( a, b ) {
if ( shouldError ) { if ( shouldError ) {
deepEqual( [ a, b ], expected, code + " => reject" ); assert.deepEqual( [ a, b ], expected, code + " => reject" );
} else { } else {
ok( false, code + " => reject" ); assert.ok( false, code + " => reject" );
} }
}).progress(function( a, b ) { }).progress(function( a, b ) {
deepEqual( [ a, b ], expectedNotify, code + " => progress" ); assert.deepEqual( [ a, b ], expectedNotify, code + " => progress" );
strictEqual( this[ 0 ], expectedNotify[ 0 ] ? context1 : undefined, code + " => first context OK" ); assert.strictEqual( this[ 0 ], expectedNotify[ 0 ] ? context1 : undefined, code + " => first context OK" );
strictEqual( this[ 1 ], expectedNotify[ 1 ] ? context2 : undefined, code + " => second context OK" ); assert.strictEqual( this[ 1 ], expectedNotify[ 1 ] ? context2 : undefined, code + " => second context OK" );
}).always( restart ); }).always( restart );
}); });
}); });
@ -787,69 +787,69 @@ test( "jQuery.when - joined", function() {
deferreds.eventuallyRejected.reject( 0 ); deferreds.eventuallyRejected.reject( 0 );
}); });
test( "jQuery.when - resolved", function() { QUnit.test( "jQuery.when - resolved", function( assert ) {
expect( 6 ); assert.expect( 6 );
var a = jQuery.Deferred().notify( 1 ).resolve( 4 ), var a = jQuery.Deferred().notify( 1 ).resolve( 4 ),
b = jQuery.Deferred().notify( 2 ).resolve( 5 ), b = jQuery.Deferred().notify( 2 ).resolve( 5 ),
c = jQuery.Deferred().notify( 3 ).resolve( 6 ); c = jQuery.Deferred().notify( 3 ).resolve( 6 );
jQuery.when( a, b, c ).progress(function( a, b, c ) { jQuery.when( a, b, c ).progress(function( a, b, c ) {
strictEqual( a, 1, "first notify value ok" ); assert.strictEqual( a, 1, "first notify value ok" );
strictEqual( b, 2, "second notify value ok" ); assert.strictEqual( b, 2, "second notify value ok" );
strictEqual( c, 3, "third notify value ok" ); assert.strictEqual( c, 3, "third notify value ok" );
}).done(function( a, b, c ) { }).done(function( a, b, c ) {
strictEqual( a, 4, "first resolve value ok" ); assert.strictEqual( a, 4, "first resolve value ok" );
strictEqual( b, 5, "second resolve value ok" ); assert.strictEqual( b, 5, "second resolve value ok" );
strictEqual( c, 6, "third resolve value ok" ); assert.strictEqual( c, 6, "third resolve value ok" );
}).fail(function() { }).fail(function() {
ok( false, "Error on resolve" ); assert.ok( false, "Error on resolve" );
}); });
}); });
test( "jQuery.when - filtering", function() { QUnit.test( "jQuery.when - filtering", function( assert ) {
expect( 2 ); assert.expect( 2 );
function increment( x ) { function increment( x ) {
return x + 1; return x + 1;
} }
stop(); QUnit.stop();
jQuery.when( jQuery.when(
jQuery.Deferred().resolve( 3 ).then( increment ), jQuery.Deferred().resolve( 3 ).then( increment ),
jQuery.Deferred().reject( 5 ).then( null, increment ) jQuery.Deferred().reject( 5 ).then( null, increment )
).done(function( four, six ) { ).done(function( four, six ) {
strictEqual( four, 4, "resolved value incremented" ); assert.strictEqual( four, 4, "resolved value incremented" );
strictEqual( six, 6, "rejected value incremented" ); assert.strictEqual( six, 6, "rejected value incremented" );
start(); QUnit.start();
}); });
}); });
test( "jQuery.when - exceptions", function() { QUnit.test( "jQuery.when - exceptions", function( assert ) {
expect( 2 ); assert.expect( 2 );
function woops() { function woops() {
throw "exception thrown"; throw "exception thrown";
} }
stop(); QUnit.stop();
jQuery.Deferred().resolve().then( woops ).fail(function( doneException ) { jQuery.Deferred().resolve().then( woops ).fail(function( doneException ) {
strictEqual( doneException, "exception thrown", "throwing in done handler" ); assert.strictEqual( doneException, "exception thrown", "throwing in done handler" );
jQuery.Deferred().reject().then( null, woops ).fail(function( failException ) { jQuery.Deferred().reject().then( null, woops ).fail(function( failException ) {
strictEqual( failException, "exception thrown", "throwing in fail handler" ); assert.strictEqual( failException, "exception thrown", "throwing in fail handler" );
start(); QUnit.start();
}); });
}); });
}); });
test( "jQuery.when - chaining", function() { QUnit.test( "jQuery.when - chaining", function( assert ) {
expect( 4 ); assert.expect( 4 );
var defer = jQuery.Deferred(); var defer = jQuery.Deferred();
@ -861,7 +861,7 @@ test( "jQuery.when - chaining", function() {
return Promise.resolve( "std deferred" ); return Promise.resolve( "std deferred" );
} }
stop(); QUnit.stop();
jQuery.when( jQuery.when(
jQuery.Deferred().resolve( 3 ).then( chain ), jQuery.Deferred().resolve( 3 ).then( chain ),
@ -869,11 +869,11 @@ test( "jQuery.when - chaining", function() {
jQuery.Deferred().resolve( 3 ).then( chainStandard ), jQuery.Deferred().resolve( 3 ).then( chainStandard ),
jQuery.Deferred().reject( 5 ).then( null, chainStandard ) jQuery.Deferred().reject( 5 ).then( null, chainStandard )
).done(function( v1, v2, s1, s2 ) { ).done(function( v1, v2, s1, s2 ) {
strictEqual( v1, "other deferred", "chaining in done handler" ); assert.strictEqual( v1, "other deferred", "chaining in done handler" );
strictEqual( v2, "other deferred", "chaining in fail handler" ); assert.strictEqual( v2, "other deferred", "chaining in fail handler" );
strictEqual( s1, "std deferred", "chaining thenable in done handler" ); assert.strictEqual( s1, "std deferred", "chaining thenable in done handler" );
strictEqual( s2, "std deferred", "chaining thenable in fail handler" ); assert.strictEqual( s2, "std deferred", "chaining thenable in fail handler" );
start(); QUnit.start();
}); });
defer.resolve( "other deferred" ); defer.resolve( "other deferred" );

View File

@ -1,2 +1,2 @@
module("deprecated", { teardown: moduleTeardown }); QUnit.module("deprecated", { teardown: moduleTeardown });

View File

@ -4,7 +4,7 @@ if ( !jQuery.fn.width ) {
return; return;
} }
module("dimensions", { teardown: moduleTeardown }); QUnit.module("dimensions", { teardown: moduleTeardown });
function pass( val ) { function pass( val ) {
return val; return val;
@ -21,127 +21,127 @@ function fn( val ) {
pass and fn can be used to test passing functions to setters pass and fn can be used to test passing functions to setters
See testWidth below for an example See testWidth below for an example
pass( value ); pass( value, assert );
This function returns whatever value is passed in This function returns whatever value is passed in
fn( value ); fn( value, assert );
Returns a function that returns the value Returns a function that returns the value
*/ */
function testWidth( val ) { function testWidth( val, assert ) {
expect(9); assert.expect(9);
var $div, blah; var $div, blah;
$div = jQuery("#nothiddendiv"); $div = jQuery("#nothiddendiv");
$div.width( val(30) ); $div.width( val(30) );
equal($div.width(), 30, "Test set to 30 correctly"); assert.equal($div.width(), 30, "Test set to 30 correctly");
$div.hide(); $div.hide();
equal($div.width(), 30, "Test hidden div"); assert.equal($div.width(), 30, "Test hidden div");
$div.show(); $div.show();
$div.width( val(-1) ); // handle negative numbers by setting to 0 #11604 $div.width( val(-1) ); // handle negative numbers by setting to 0 #11604
equal($div.width(), 0, "Test negative width normalized to 0"); assert.equal($div.width(), 0, "Test negative width normalized to 0");
$div.css("padding", "20px"); $div.css("padding", "20px");
equal($div.width(), 0, "Test padding specified with pixels"); assert.equal($div.width(), 0, "Test padding specified with pixels");
$div.css("border", "2px solid #fff"); $div.css("border", "2px solid #fff");
equal($div.width(), 0, "Test border specified with pixels"); assert.equal($div.width(), 0, "Test border specified with pixels");
$div.css({ "display": "", "border": "", "padding": "" }); $div.css({ "display": "", "border": "", "padding": "" });
jQuery("#nothiddendivchild").css({ "width": 20, "padding": "3px", "border": "2px solid #fff" }); jQuery("#nothiddendivchild").css({ "width": 20, "padding": "3px", "border": "2px solid #fff" });
equal(jQuery("#nothiddendivchild").width(), 20, "Test child width with border and padding"); assert.equal(jQuery("#nothiddendivchild").width(), 20, "Test child width with border and padding");
jQuery("#nothiddendiv, #nothiddendivchild").css({ "border": "", "padding": "", "width": "" }); jQuery("#nothiddendiv, #nothiddendivchild").css({ "border": "", "padding": "", "width": "" });
blah = jQuery("blah"); blah = jQuery("blah");
equal( blah.width( val(10) ), blah, "Make sure that setting a width on an empty set returns the set." ); assert.equal( blah.width( val(10) ), blah, "Make sure that setting a width on an empty set returns the set." );
equal( blah.width(), null, "Make sure 'null' is returned on an empty set"); assert.equal( blah.width(), null, "Make sure 'null' is returned on an empty set");
equal( jQuery(window).width(), document.documentElement.clientWidth, "Window width is equal to width reported by window/document." ); assert.equal( jQuery(window).width(), document.documentElement.clientWidth, "Window width is equal to width reported by window/document." );
QUnit.expectJqData( this, $div[0], "olddisplay" ); QUnit.expectJqData( this, $div[0], "olddisplay" );
} }
test("width()", function() { QUnit.test("width()", function( assert ) {
testWidth( pass ); testWidth( pass, assert );
}); });
test("width(Function)", function() { QUnit.test("width(Function)", function( assert ) {
testWidth( fn ); testWidth( fn, assert );
}); });
test("width(Function(args))", function() { QUnit.test("width(Function(args))", function( assert ) {
expect( 2 ); assert.expect( 2 );
var $div = jQuery("#nothiddendiv"); var $div = jQuery("#nothiddendiv");
$div.width( 30 ).width(function(i, width) { $div.width( 30 ).width(function(i, width) {
equal( width, 30, "Make sure previous value is correct." ); assert.equal( width, 30, "Make sure previous value is correct." );
return width + 1; return width + 1;
}); });
equal( $div.width(), 31, "Make sure value was modified correctly." ); assert.equal( $div.width(), 31, "Make sure value was modified correctly." );
}); });
function testHeight( val ) { function testHeight( val, assert ) {
expect(9); assert.expect(9);
var $div, blah; var $div, blah;
$div = jQuery("#nothiddendiv"); $div = jQuery("#nothiddendiv");
$div.height( val(30) ); $div.height( val(30) );
equal($div.height(), 30, "Test set to 30 correctly"); assert.equal($div.height(), 30, "Test set to 30 correctly");
$div.hide(); $div.hide();
equal($div.height(), 30, "Test hidden div"); assert.equal($div.height(), 30, "Test hidden div");
$div.show(); $div.show();
$div.height( val(-1) ); // handle negative numbers by setting to 0 #11604 $div.height( val(-1) ); // handle negative numbers by setting to 0 #11604
equal($div.height(), 0, "Test negative height normalized to 0"); assert.equal($div.height(), 0, "Test negative height normalized to 0");
$div.css("padding", "20px"); $div.css("padding", "20px");
equal($div.height(), 0, "Test padding specified with pixels"); assert.equal($div.height(), 0, "Test padding specified with pixels");
$div.css("border", "2px solid #fff"); $div.css("border", "2px solid #fff");
equal($div.height(), 0, "Test border specified with pixels"); assert.equal($div.height(), 0, "Test border specified with pixels");
$div.css({ "display": "", "border": "", "padding": "", "height": "1px" }); $div.css({ "display": "", "border": "", "padding": "", "height": "1px" });
jQuery("#nothiddendivchild").css({ "height": 20, "padding": "3px", "border": "2px solid #fff" }); jQuery("#nothiddendivchild").css({ "height": 20, "padding": "3px", "border": "2px solid #fff" });
equal(jQuery("#nothiddendivchild").height(), 20, "Test child height with border and padding"); assert.equal(jQuery("#nothiddendivchild").height(), 20, "Test child height with border and padding");
jQuery("#nothiddendiv, #nothiddendivchild").css({ "border": "", "padding": "", "height": "" }); jQuery("#nothiddendiv, #nothiddendivchild").css({ "border": "", "padding": "", "height": "" });
blah = jQuery("blah"); blah = jQuery("blah");
equal( blah.height( val(10) ), blah, "Make sure that setting a height on an empty set returns the set." ); assert.equal( blah.height( val(10) ), blah, "Make sure that setting a height on an empty set returns the set." );
equal( blah.height(), null, "Make sure 'null' is returned on an empty set"); assert.equal( blah.height(), null, "Make sure 'null' is returned on an empty set");
equal( jQuery(window).height(), document.documentElement.clientHeight, "Window width is equal to width reported by window/document." ); assert.equal( jQuery(window).height(), document.documentElement.clientHeight, "Window width is equal to width reported by window/document." );
QUnit.expectJqData( this, $div[0], "olddisplay" ); QUnit.expectJqData( this, $div[0], "olddisplay" );
} }
test("height()", function() { QUnit.test("height()", function( assert ) {
testHeight( pass ); testHeight( pass, assert );
}); });
test("height(Function)", function() { QUnit.test("height(Function)", function( assert ) {
testHeight( fn ); testHeight( fn, assert );
}); });
test("height(Function(args))", function() { QUnit.test("height(Function(args))", function( assert ) {
expect( 2 ); assert.expect( 2 );
var $div = jQuery("#nothiddendiv"); var $div = jQuery("#nothiddendiv");
$div.height( 30 ).height(function(i, height) { $div.height( 30 ).height(function(i, height) {
equal( height, 30, "Make sure previous value is correct." ); assert.equal( height, 30, "Make sure previous value is correct." );
return height + 1; return height + 1;
}); });
equal( $div.height(), 31, "Make sure value was modified correctly." ); assert.equal( $div.height(), 31, "Make sure value was modified correctly." );
}); });
test("innerWidth()", function() { QUnit.test("innerWidth()", function( assert ) {
expect( 6 ); assert.expect( 6 );
var $div, div, var $div, div,
$win = jQuery( window ), $win = jQuery( window ),
$doc = jQuery( document ); $doc = jQuery( document );
equal( jQuery( window ).innerWidth(), $win.width(), "Test on window" ); assert.equal( jQuery( window ).innerWidth(), $win.width(), "Test on window" );
equal( jQuery( document ).innerWidth(), $doc.width(), "Test on document" ); assert.equal( jQuery( document ).innerWidth(), $doc.width(), "Test on document" );
$div = jQuery( "#nothiddendiv" ); $div = jQuery( "#nothiddendiv" );
$div.css({ $div.css({
@ -150,11 +150,11 @@ test("innerWidth()", function() {
"width": 30 "width": 30
}); });
equal( $div.innerWidth(), 30, "Test with margin and border" ); assert.equal( $div.innerWidth(), 30, "Test with margin and border" );
$div.css( "padding", "20px" ); $div.css( "padding", "20px" );
equal( $div.innerWidth(), 70, "Test with margin, border and padding" ); assert.equal( $div.innerWidth(), 70, "Test with margin, border and padding" );
$div.hide(); $div.hide();
equal( $div.innerWidth(), 70, "Test hidden div" ); assert.equal( $div.innerWidth(), 70, "Test hidden div" );
// reset styles // reset styles
$div.css({ "display": "", "border": "", "padding": "", "width": "", "height": "" }); $div.css({ "display": "", "border": "", "padding": "", "width": "", "height": "" });
@ -162,21 +162,21 @@ test("innerWidth()", function() {
div = jQuery( "<div>" ); div = jQuery( "<div>" );
// Temporarily require 0 for backwards compat - should be auto // Temporarily require 0 for backwards compat - should be auto
equal( div.innerWidth(), 0, "Make sure that disconnected nodes are handled." ); assert.equal( div.innerWidth(), 0, "Make sure that disconnected nodes are handled." );
div.remove(); div.remove();
QUnit.expectJqData( this, $div[ 0 ], "olddisplay" ); QUnit.expectJqData( this, $div[ 0 ], "olddisplay" );
}); });
test("innerHeight()", function() { QUnit.test("innerHeight()", function( assert ) {
expect( 6 ); assert.expect( 6 );
var $div, div, var $div, div,
$win = jQuery( window ), $win = jQuery( window ),
$doc = jQuery( document ); $doc = jQuery( document );
equal( jQuery( window ).innerHeight(), $win.height(), "Test on window" ); assert.equal( jQuery( window ).innerHeight(), $win.height(), "Test on window" );
equal( jQuery( document ).innerHeight(), $doc.height(), "Test on document" ); assert.equal( jQuery( document ).innerHeight(), $doc.height(), "Test on document" );
$div = jQuery( "#nothiddendiv" ); $div = jQuery( "#nothiddendiv" );
$div.css({ $div.css({
@ -185,11 +185,11 @@ test("innerHeight()", function() {
"height": 30 "height": 30
}); });
equal( $div.innerHeight(), 30, "Test with margin and border" ); assert.equal( $div.innerHeight(), 30, "Test with margin and border" );
$div.css( "padding", "20px" ); $div.css( "padding", "20px" );
equal( $div.innerHeight(), 70, "Test with margin, border and padding" ); assert.equal( $div.innerHeight(), 70, "Test with margin, border and padding" );
$div.hide(); $div.hide();
equal( $div.innerHeight(), 70, "Test hidden div" ); assert.equal( $div.innerHeight(), 70, "Test hidden div" );
// reset styles // reset styles
$div.css({ "display": "", "border": "", "padding": "", "width": "", "height": "" }); $div.css({ "display": "", "border": "", "padding": "", "width": "", "height": "" });
@ -197,38 +197,38 @@ test("innerHeight()", function() {
div = jQuery( "<div>" ); div = jQuery( "<div>" );
// Temporarily require 0 for backwards compat - should be auto // Temporarily require 0 for backwards compat - should be auto
equal( div.innerHeight(), 0, "Make sure that disconnected nodes are handled." ); assert.equal( div.innerHeight(), 0, "Make sure that disconnected nodes are handled." );
div.remove(); div.remove();
QUnit.expectJqData( this, $div[ 0 ], "olddisplay" ); QUnit.expectJqData( this, $div[ 0 ], "olddisplay" );
}); });
test("outerWidth()", function() { QUnit.test("outerWidth()", function( assert ) {
expect( 11 ); assert.expect( 11 );
var $div, div, var $div, div,
$win = jQuery( window ), $win = jQuery( window ),
$doc = jQuery( document ); $doc = jQuery( document );
equal( jQuery( window ).outerWidth(), $win.width(), "Test on window without margin option" ); assert.equal( jQuery( window ).outerWidth(), $win.width(), "Test on window without margin option" );
equal( jQuery( window ).outerWidth( true ), $win.width(), "Test on window with margin option" ); assert.equal( jQuery( window ).outerWidth( true ), $win.width(), "Test on window with margin option" );
equal( jQuery( document ).outerWidth(), $doc.width(), "Test on document without margin option" ); assert.equal( jQuery( document ).outerWidth(), $doc.width(), "Test on document without margin option" );
equal( jQuery( document ).outerWidth( true ), $doc.width(), "Test on document with margin option" ); assert.equal( jQuery( document ).outerWidth( true ), $doc.width(), "Test on document with margin option" );
$div = jQuery( "#nothiddendiv" ); $div = jQuery( "#nothiddendiv" );
$div.css( "width", 30 ); $div.css( "width", 30 );
equal( $div.outerWidth(), 30, "Test with only width set" ); assert.equal( $div.outerWidth(), 30, "Test with only width set" );
$div.css( "padding", "20px" ); $div.css( "padding", "20px" );
equal( $div.outerWidth(), 70, "Test with padding" ); assert.equal( $div.outerWidth(), 70, "Test with padding" );
$div.css( "border", "2px solid #fff" ); $div.css( "border", "2px solid #fff" );
equal( $div.outerWidth(), 74, "Test with padding and border" ); assert.equal( $div.outerWidth(), 74, "Test with padding and border" );
$div.css( "margin", "10px" ); $div.css( "margin", "10px" );
equal( $div.outerWidth(), 74, "Test with padding, border and margin without margin option" ); assert.equal( $div.outerWidth(), 74, "Test with padding, border and margin without margin option" );
$div.css( "position", "absolute" ); $div.css( "position", "absolute" );
equal( $div.outerWidth( true ), 94, "Test with padding, border and margin with margin option" ); assert.equal( $div.outerWidth( true ), 94, "Test with padding, border and margin with margin option" );
$div.hide(); $div.hide();
equal( $div.outerWidth( true ), 94, "Test hidden div with padding, border and margin with margin option" ); assert.equal( $div.outerWidth( true ), 94, "Test hidden div with padding, border and margin with margin option" );
// reset styles // reset styles
$div.css({ "position": "", "display": "", "border": "", "padding": "", "width": "", "height": "" }); $div.css({ "position": "", "display": "", "border": "", "padding": "", "width": "", "height": "" });
@ -236,14 +236,14 @@ test("outerWidth()", function() {
div = jQuery( "<div>" ); div = jQuery( "<div>" );
// Temporarily require 0 for backwards compat - should be auto // Temporarily require 0 for backwards compat - should be auto
equal( div.outerWidth(), 0, "Make sure that disconnected nodes are handled." ); assert.equal( div.outerWidth(), 0, "Make sure that disconnected nodes are handled." );
div.remove(); div.remove();
QUnit.expectJqData( this, $div[ 0 ], "olddisplay" ); QUnit.expectJqData( this, $div[ 0 ], "olddisplay" );
}); });
test("child of a hidden elem (or unconnected node) has accurate inner/outer/Width()/Height() see #9441 #9300", function() { QUnit.test("child of a hidden elem (or unconnected node) has accurate inner/outer/Width()/Height() see #9441 #9300", function( assert ) {
expect(16); assert.expect(16);
// setup html // setup html
var $divNormal = jQuery("<div>").css({ "width": "100px", "height": "100px", "border": "10px solid white", "padding": "2px", "margin": "3px" }), var $divNormal = jQuery("<div>").css({ "width": "100px", "height": "100px", "border": "10px solid white", "padding": "2px", "margin": "3px" }),
@ -253,38 +253,38 @@ test("child of a hidden elem (or unconnected node) has accurate inner/outer/Widt
$divNormal.appendTo("body"); $divNormal.appendTo("body");
// tests that child div of a hidden div works the same as a normal div // tests that child div of a hidden div works the same as a normal div
equal( $divChild.width(), $divNormal.width(), "child of a hidden element width() is wrong see #9441" ); assert.equal( $divChild.width(), $divNormal.width(), "child of a hidden element width() is wrong see #9441" );
equal( $divChild.innerWidth(), $divNormal.innerWidth(), "child of a hidden element innerWidth() is wrong see #9441" ); assert.equal( $divChild.innerWidth(), $divNormal.innerWidth(), "child of a hidden element innerWidth() is wrong see #9441" );
equal( $divChild.outerWidth(), $divNormal.outerWidth(), "child of a hidden element outerWidth() is wrong see #9441" ); assert.equal( $divChild.outerWidth(), $divNormal.outerWidth(), "child of a hidden element outerWidth() is wrong see #9441" );
equal( $divChild.outerWidth(true), $divNormal.outerWidth( true ), "child of a hidden element outerWidth( true ) is wrong see #9300" ); assert.equal( $divChild.outerWidth(true), $divNormal.outerWidth( true ), "child of a hidden element outerWidth( true ) is wrong see #9300" );
// Support: IE 10-11, Edge // Support: IE 10-11, Edge
// Child height is not always decimal // Child height is not always decimal
equal( $divChild.height().toFixed( 3 ), $divNormal.height().toFixed( 3 ), "child of a hidden element height() is wrong see #9441" ); assert.equal( $divChild.height().toFixed( 3 ), $divNormal.height().toFixed( 3 ), "child of a hidden element height() is wrong see #9441" );
equal( $divChild.innerHeight().toFixed( 3 ), $divNormal.innerHeight().toFixed( 3 ), "child of a hidden element innerHeight() is wrong see #9441" ); assert.equal( $divChild.innerHeight().toFixed( 3 ), $divNormal.innerHeight().toFixed( 3 ), "child of a hidden element innerHeight() is wrong see #9441" );
equal( $divChild.outerHeight().toFixed( 3 ), $divNormal.outerHeight().toFixed( 3 ), "child of a hidden element outerHeight() is wrong see #9441" ); assert.equal( $divChild.outerHeight().toFixed( 3 ), $divNormal.outerHeight().toFixed( 3 ), "child of a hidden element outerHeight() is wrong see #9441" );
equal( $divChild.outerHeight( true ).toFixed( 3 ), $divNormal.outerHeight( true ).toFixed( 3 ), "child of a hidden element outerHeight( true ) is wrong see #9300" ); assert.equal( $divChild.outerHeight( true ).toFixed( 3 ), $divNormal.outerHeight( true ).toFixed( 3 ), "child of a hidden element outerHeight( true ) is wrong see #9300" );
// tests that child div of an unconnected div works the same as a normal div // tests that child div of an unconnected div works the same as a normal div
equal( $divUnconnected.width(), $divNormal.width(), "unconnected element width() is wrong see #9441" ); assert.equal( $divUnconnected.width(), $divNormal.width(), "unconnected element width() is wrong see #9441" );
equal( $divUnconnected.innerWidth(), $divNormal.innerWidth(), "unconnected element innerWidth() is wrong see #9441" ); assert.equal( $divUnconnected.innerWidth(), $divNormal.innerWidth(), "unconnected element innerWidth() is wrong see #9441" );
equal( $divUnconnected.outerWidth(), $divNormal.outerWidth(), "unconnected element outerWidth() is wrong see #9441" ); assert.equal( $divUnconnected.outerWidth(), $divNormal.outerWidth(), "unconnected element outerWidth() is wrong see #9441" );
equal( $divUnconnected.outerWidth(true), $divNormal.outerWidth( true ), "unconnected element outerWidth( true ) is wrong see #9300" ); assert.equal( $divUnconnected.outerWidth(true), $divNormal.outerWidth( true ), "unconnected element outerWidth( true ) is wrong see #9300" );
// Support: IE 10-11, Edge // Support: IE 10-11, Edge
// Child height is not always decimal // Child height is not always decimal
equal( $divUnconnected.height().toFixed( 3 ), $divNormal.height().toFixed( 3 ), "unconnected element height() is wrong see #9441" ); assert.equal( $divUnconnected.height().toFixed( 3 ), $divNormal.height().toFixed( 3 ), "unconnected element height() is wrong see #9441" );
equal( $divUnconnected.innerHeight().toFixed( 3 ), $divNormal.innerHeight().toFixed( 3 ), "unconnected element innerHeight() is wrong see #9441" ); assert.equal( $divUnconnected.innerHeight().toFixed( 3 ), $divNormal.innerHeight().toFixed( 3 ), "unconnected element innerHeight() is wrong see #9441" );
equal( $divUnconnected.outerHeight().toFixed( 3 ), $divNormal.outerHeight().toFixed( 3 ), "unconnected element outerHeight() is wrong see #9441" ); assert.equal( $divUnconnected.outerHeight().toFixed( 3 ), $divNormal.outerHeight().toFixed( 3 ), "unconnected element outerHeight() is wrong see #9441" );
equal( $divUnconnected.outerHeight( true ).toFixed( 3 ), $divNormal.outerHeight( true ).toFixed( 3 ), "unconnected element outerHeight( true ) is wrong see #9300" ); assert.equal( $divUnconnected.outerHeight( true ).toFixed( 3 ), $divNormal.outerHeight( true ).toFixed( 3 ), "unconnected element outerHeight( true ) is wrong see #9300" );
// teardown html // teardown html
$divHiddenParent.remove(); $divHiddenParent.remove();
$divNormal.remove(); $divNormal.remove();
}); });
test("getting dimensions shouldn't modify runtimeStyle see #9233", function() { QUnit.test("getting dimensions shouldn't modify runtimeStyle see #9233", function( assert ) {
expect( 1 ); assert.expect( 1 );
var $div = jQuery( "<div>" ).appendTo( "#qunit-fixture" ), var $div = jQuery( "<div>" ).appendTo( "#qunit-fixture" ),
div = $div.get( 0 ), div = $div.get( 0 ),
@ -298,16 +298,16 @@ test("getting dimensions shouldn't modify runtimeStyle see #9233", function() {
$div.outerWidth( true ); $div.outerWidth( true );
if ( runtimeStyle ) { if ( runtimeStyle ) {
equal( div.runtimeStyle.left, "11em", "getting dimensions modifies runtimeStyle, see #9233" ); assert.equal( div.runtimeStyle.left, "11em", "getting dimensions modifies runtimeStyle, see #9233" );
} else { } else {
ok( true, "this browser doesn't support runtimeStyle, see #9233" ); assert.ok( true, "this browser doesn't support runtimeStyle, see #9233" );
} }
$div.remove(); $div.remove();
}); });
test( "table dimensions", function() { QUnit.test( "table dimensions", function( assert ) {
expect( 2 ); assert.expect( 2 );
var table = jQuery("<table><colgroup><col/><col/></colgroup><tbody><tr><td></td><td>a</td></tr><tr><td></td><td>a</td></tr></tbody></table>").appendTo("#qunit-fixture"), var table = jQuery("<table><colgroup><col/><col/></colgroup><tbody><tr><td></td><td>a</td></tr><tr><td></td><td>a</td></tr></tbody></table>").appendTo("#qunit-fixture"),
tdElem = table.find("td").first(), tdElem = table.find("td").first(),
@ -315,12 +315,12 @@ test( "table dimensions", function() {
table.find("td").css({ "margin": 0, "padding": 0 }); table.find("td").css({ "margin": 0, "padding": 0 });
equal( tdElem.width(), tdElem.width(), "width() doesn't alter dimension values of empty cells, see #11293" ); assert.equal( tdElem.width(), tdElem.width(), "width() doesn't alter dimension values of empty cells, see #11293" );
equal( colElem.width(), 300, "col elements have width(), see #12243" ); assert.equal( colElem.width(), 300, "col elements have width(), see #12243" );
}); });
test("box-sizing:border-box child of a hidden elem (or unconnected node) has accurate inner/outer/Width()/Height() see #10413", function() { QUnit.test("box-sizing:border-box child of a hidden elem (or unconnected node) has accurate inner/outer/Width()/Height() see #10413", function( assert ) {
expect(16); assert.expect(16);
// setup html // setup html
var $divNormal = jQuery("<div>").css({ "boxSizing": "border-box", "width": "100px", "height": "100px", "border": "10px solid white", "padding": "2px", "margin": "3px" }), var $divNormal = jQuery("<div>").css({ "boxSizing": "border-box", "width": "100px", "height": "100px", "border": "10px solid white", "padding": "2px", "margin": "3px" }),
@ -330,61 +330,61 @@ test("box-sizing:border-box child of a hidden elem (or unconnected node) has acc
$divNormal.appendTo("body"); $divNormal.appendTo("body");
// tests that child div of a hidden div works the same as a normal div // tests that child div of a hidden div works the same as a normal div
equal( $divChild.width(), $divNormal.width(), "child of a hidden element width() is wrong see #10413" ); assert.equal( $divChild.width(), $divNormal.width(), "child of a hidden element width() is wrong see #10413" );
equal( $divChild.innerWidth(), $divNormal.innerWidth(), "child of a hidden element innerWidth() is wrong see #10413" ); assert.equal( $divChild.innerWidth(), $divNormal.innerWidth(), "child of a hidden element innerWidth() is wrong see #10413" );
equal( $divChild.outerWidth(), $divNormal.outerWidth(), "child of a hidden element outerWidth() is wrong see #10413" ); assert.equal( $divChild.outerWidth(), $divNormal.outerWidth(), "child of a hidden element outerWidth() is wrong see #10413" );
equal( $divChild.outerWidth(true), $divNormal.outerWidth( true ), "child of a hidden element outerWidth( true ) is wrong see #10413" ); assert.equal( $divChild.outerWidth(true), $divNormal.outerWidth( true ), "child of a hidden element outerWidth( true ) is wrong see #10413" );
// Support: IE 10-11, Edge // Support: IE 10-11, Edge
// Child height is not always decimal // Child height is not always decimal
equal( $divChild.height().toFixed( 3 ), $divNormal.height().toFixed( 3 ), "child of a hidden element height() is wrong see #10413" ); assert.equal( $divChild.height().toFixed( 3 ), $divNormal.height().toFixed( 3 ), "child of a hidden element height() is wrong see #10413" );
equal( $divChild.innerHeight().toFixed( 3 ), $divNormal.innerHeight().toFixed( 3 ), "child of a hidden element innerHeight() is wrong see #10413" ); assert.equal( $divChild.innerHeight().toFixed( 3 ), $divNormal.innerHeight().toFixed( 3 ), "child of a hidden element innerHeight() is wrong see #10413" );
equal( $divChild.outerHeight().toFixed( 3 ), $divNormal.outerHeight().toFixed( 3 ), "child of a hidden element outerHeight() is wrong see #10413" ); assert.equal( $divChild.outerHeight().toFixed( 3 ), $divNormal.outerHeight().toFixed( 3 ), "child of a hidden element outerHeight() is wrong see #10413" );
equal( $divChild.outerHeight( true ).toFixed( 3 ), $divNormal.outerHeight( true ).toFixed( 3 ), "child of a hidden element outerHeight( true ) is wrong see #10413" ); assert.equal( $divChild.outerHeight( true ).toFixed( 3 ), $divNormal.outerHeight( true ).toFixed( 3 ), "child of a hidden element outerHeight( true ) is wrong see #10413" );
// tests that child div of an unconnected div works the same as a normal div // tests that child div of an unconnected div works the same as a normal div
equal( $divUnconnected.width(), $divNormal.width(), "unconnected element width() is wrong see #10413" ); assert.equal( $divUnconnected.width(), $divNormal.width(), "unconnected element width() is wrong see #10413" );
equal( $divUnconnected.innerWidth(), $divNormal.innerWidth(), "unconnected element innerWidth() is wrong see #10413" ); assert.equal( $divUnconnected.innerWidth(), $divNormal.innerWidth(), "unconnected element innerWidth() is wrong see #10413" );
equal( $divUnconnected.outerWidth(), $divNormal.outerWidth(), "unconnected element outerWidth() is wrong see #10413" ); assert.equal( $divUnconnected.outerWidth(), $divNormal.outerWidth(), "unconnected element outerWidth() is wrong see #10413" );
equal( $divUnconnected.outerWidth(true), $divNormal.outerWidth( true ), "unconnected element outerWidth( true ) is wrong see #10413" ); assert.equal( $divUnconnected.outerWidth(true), $divNormal.outerWidth( true ), "unconnected element outerWidth( true ) is wrong see #10413" );
// Support: IE 10-11, Edge // Support: IE 10-11, Edge
// Child height is not always decimal // Child height is not always decimal
equal( $divUnconnected.height().toFixed( 3 ), $divNormal.height().toFixed( 3 ), "unconnected element height() is wrong see #10413" ); assert.equal( $divUnconnected.height().toFixed( 3 ), $divNormal.height().toFixed( 3 ), "unconnected element height() is wrong see #10413" );
equal( $divUnconnected.innerHeight().toFixed( 3 ), $divNormal.innerHeight().toFixed( 3 ), "unconnected element innerHeight() is wrong see #10413" ); assert.equal( $divUnconnected.innerHeight().toFixed( 3 ), $divNormal.innerHeight().toFixed( 3 ), "unconnected element innerHeight() is wrong see #10413" );
equal( $divUnconnected.outerHeight().toFixed( 3 ), $divNormal.outerHeight().toFixed( 3 ), "unconnected element outerHeight() is wrong see #10413" ); assert.equal( $divUnconnected.outerHeight().toFixed( 3 ), $divNormal.outerHeight().toFixed( 3 ), "unconnected element outerHeight() is wrong see #10413" );
equal( $divUnconnected.outerHeight( true ).toFixed( 3 ), $divNormal.outerHeight( true ).toFixed( 3 ), "unconnected element outerHeight( true ) is wrong see #10413" ); assert.equal( $divUnconnected.outerHeight( true ).toFixed( 3 ), $divNormal.outerHeight( true ).toFixed( 3 ), "unconnected element outerHeight( true ) is wrong see #10413" );
// teardown html // teardown html
$divHiddenParent.remove(); $divHiddenParent.remove();
$divNormal.remove(); $divNormal.remove();
}); });
test("outerHeight()", function() { QUnit.test("outerHeight()", function( assert ) {
expect( 11 ); assert.expect( 11 );
var $div, div, var $div, div,
$win = jQuery( window ), $win = jQuery( window ),
$doc = jQuery( document ); $doc = jQuery( document );
equal( jQuery( window ).outerHeight(), $win.height(), "Test on window without margin option" ); assert.equal( jQuery( window ).outerHeight(), $win.height(), "Test on window without margin option" );
equal( jQuery( window ).outerHeight( true ), $win.height(), "Test on window with margin option" ); assert.equal( jQuery( window ).outerHeight( true ), $win.height(), "Test on window with margin option" );
equal( jQuery( document ).outerHeight(), $doc.height(), "Test on document without margin option" ); assert.equal( jQuery( document ).outerHeight(), $doc.height(), "Test on document without margin option" );
equal( jQuery( document ).outerHeight( true ), $doc.height(), "Test on document with margin option" ); assert.equal( jQuery( document ).outerHeight( true ), $doc.height(), "Test on document with margin option" );
$div = jQuery( "#nothiddendiv" ); $div = jQuery( "#nothiddendiv" );
$div.css( "height", 30 ); $div.css( "height", 30 );
equal( $div.outerHeight(), 30, "Test with only width set" ); assert.equal( $div.outerHeight(), 30, "Test with only width set" );
$div.css( "padding", "20px" ); $div.css( "padding", "20px" );
equal( $div.outerHeight(), 70, "Test with padding" ); assert.equal( $div.outerHeight(), 70, "Test with padding" );
$div.css( "border", "2px solid #fff" ); $div.css( "border", "2px solid #fff" );
equal( $div.outerHeight(), 74, "Test with padding and border" ); assert.equal( $div.outerHeight(), 74, "Test with padding and border" );
$div.css( "margin", "10px" ); $div.css( "margin", "10px" );
equal( $div.outerHeight(), 74, "Test with padding, border and margin without margin option" ); assert.equal( $div.outerHeight(), 74, "Test with padding, border and margin without margin option" );
equal( $div.outerHeight( true ), 94, "Test with padding, border and margin with margin option" ); assert.equal( $div.outerHeight( true ), 94, "Test with padding, border and margin with margin option" );
$div.hide(); $div.hide();
equal( $div.outerHeight( true ), 94, "Test hidden div with padding, border and margin with margin option" ); assert.equal( $div.outerHeight( true ), 94, "Test hidden div with padding, border and margin with margin option" );
// reset styles // reset styles
$div.css({ "display": "", "border": "", "padding": "", "width": "", "height": "" }); $div.css({ "display": "", "border": "", "padding": "", "width": "", "height": "" });
@ -392,78 +392,82 @@ test("outerHeight()", function() {
div = jQuery( "<div>" ); div = jQuery( "<div>" );
// Temporarily require 0 for backwards compat - should be auto // Temporarily require 0 for backwards compat - should be auto
equal( div.outerHeight(), 0, "Make sure that disconnected nodes are handled." ); assert.equal( div.outerHeight(), 0, "Make sure that disconnected nodes are handled." );
div.remove(); div.remove();
QUnit.expectJqData( this, $div[ 0 ], "olddisplay" ); QUnit.expectJqData( this, $div[ 0 ], "olddisplay" );
}); });
test("passing undefined is a setter #5571", function() { QUnit.test("passing undefined is a setter #5571", function( assert ) {
expect(4); assert.expect(4);
equal(jQuery("#nothiddendiv").height(30).height(undefined).height(), 30, ".height(undefined) is chainable (#5571)"); assert.equal(jQuery("#nothiddendiv").height(30).height(undefined).height(), 30, ".height(undefined) is chainable (#5571)");
equal(jQuery("#nothiddendiv").height(30).innerHeight(undefined).height(), 30, ".innerHeight(undefined) is chainable (#5571)"); assert.equal(jQuery("#nothiddendiv").height(30).innerHeight(undefined).height(), 30, ".innerHeight(undefined) is chainable (#5571)");
equal(jQuery("#nothiddendiv").height(30).outerHeight(undefined).height(), 30, ".outerHeight(undefined) is chainable (#5571)"); assert.equal(jQuery("#nothiddendiv").height(30).outerHeight(undefined).height(), 30, ".outerHeight(undefined) is chainable (#5571)");
equal(jQuery("#nothiddendiv").width(30).width(undefined).width(), 30, ".width(undefined) is chainable (#5571)"); assert.equal(jQuery("#nothiddendiv").width(30).width(undefined).width(), 30, ".width(undefined) is chainable (#5571)");
}); });
test( "getters on non elements should return null", function() { QUnit.test( "getters on non elements should return null", function( assert ) {
expect( 8 ); assert.expect( 8 );
var nonElem = jQuery("notAnElement"); var nonElem = jQuery("notAnElement");
strictEqual( nonElem.width(), null, ".width() is not null (#12283)" ); assert.strictEqual( nonElem.width(), null, ".width() is not null (#12283)" );
strictEqual( nonElem.innerWidth(), null, ".innerWidth() is not null (#12283)" ); assert.strictEqual( nonElem.innerWidth(), null, ".innerWidth() is not null (#12283)" );
strictEqual( nonElem.outerWidth(), null, ".outerWidth() is not null (#12283)" ); assert.strictEqual( nonElem.outerWidth(), null, ".outerWidth() is not null (#12283)" );
strictEqual( nonElem.outerWidth( true ), null, ".outerWidth(true) is not null (#12283)" ); assert.strictEqual( nonElem.outerWidth( true ), null, ".outerWidth(true) is not null (#12283)" );
strictEqual( nonElem.height(), null, ".height() is not null (#12283)" ); assert.strictEqual( nonElem.height(), null, ".height() is not null (#12283)" );
strictEqual( nonElem.innerHeight(), null, ".innerHeight() is not null (#12283)" ); assert.strictEqual( nonElem.innerHeight(), null, ".innerHeight() is not null (#12283)" );
strictEqual( nonElem.outerHeight(), null, ".outerHeight() is not null (#12283)" ); assert.strictEqual( nonElem.outerHeight(), null, ".outerHeight() is not null (#12283)" );
strictEqual( nonElem.outerHeight( true ), null, ".outerHeight(true) is not null (#12283)" ); assert.strictEqual( nonElem.outerHeight( true ), null, ".outerHeight(true) is not null (#12283)" );
}); });
test("setters with and without box-sizing:border-box", function(){ QUnit.test("setters with and without box-sizing:border-box", function( assert ){
expect(20); assert.expect(20);
// Support: Android 2.3 (-webkit-box-sizing). // Support: Android 2.3 (-webkit-box-sizing).
var el_bb = jQuery("<div style='width:114px;height:114px;margin:5px;padding:3px;border:4px solid white;-webkit-box-sizing:border-box;box-sizing:border-box;'>test</div>").appendTo("#qunit-fixture"), var el_bb = jQuery("<div style='width:114px;height:114px;margin:5px;padding:3px;border:4px solid white;-webkit-box-sizing:border-box;box-sizing:border-box;'>test</div>").appendTo("#qunit-fixture"),
el = jQuery("<div style='width:100px;height:100px;margin:5px;padding:3px;border:4px solid white;'>test</div>").appendTo("#qunit-fixture"), el = jQuery("<div style='width:100px;height:100px;margin:5px;padding:3px;border:4px solid white;'>test</div>").appendTo("#qunit-fixture"),
expected = 100; expected = 100;
equal( el_bb.width( 101 ).width(), expected + 1, "test border-box width(int) by roundtripping" ); assert.equal( el_bb.width( 101 ).width(), expected + 1, "test border-box width(int) by roundtripping" );
equal( el_bb.innerWidth( 108 ).width(), expected + 2, "test border-box innerWidth(int) by roundtripping" ); assert.equal( el_bb.innerWidth( 108 ).width(), expected + 2, "test border-box innerWidth(int) by roundtripping" );
equal( el_bb.outerWidth( 117 ).width(), expected + 3, "test border-box outerWidth(int) by roundtripping" ); assert.equal( el_bb.outerWidth( 117 ).width(), expected + 3, "test border-box outerWidth(int) by roundtripping" );
equal( el_bb.outerWidth( 118, false ).width(), expected + 4, "test border-box outerWidth(int, false) by roundtripping" ); assert.equal( el_bb.outerWidth( 118, false ).width(), expected + 4, "test border-box outerWidth(int, false) by roundtripping" );
equal( el_bb.outerWidth( 129, true ).width(), expected + 5, "test border-box innerWidth(int, true) by roundtripping" ); assert.equal( el_bb.outerWidth( 129, true ).width(), expected + 5, "test border-box innerWidth(int, true) by roundtripping" );
equal( el_bb.height( 101 ).height(), expected + 1, "test border-box height(int) by roundtripping" ); assert.equal( el_bb.height( 101 ).height(), expected + 1, "test border-box height(int) by roundtripping" );
equal( el_bb.innerHeight( 108 ).height(), expected + 2, "test border-box innerHeight(int) by roundtripping" ); assert.equal( el_bb.innerHeight( 108 ).height(), expected + 2, "test border-box innerHeight(int) by roundtripping" );
equal( el_bb.outerHeight( 117 ).height(), expected + 3, "test border-box outerHeight(int) by roundtripping" ); assert.equal( el_bb.outerHeight( 117 ).height(), expected + 3, "test border-box outerHeight(int) by roundtripping" );
equal( el_bb.outerHeight( 118, false ).height(), expected + 4, "test border-box outerHeight(int, false) by roundtripping" ); assert.equal( el_bb.outerHeight( 118, false ).height(), expected + 4, "test border-box outerHeight(int, false) by roundtripping" );
equal( el_bb.outerHeight( 129, true ).height(), expected + 5, "test border-box innerHeight(int, true) by roundtripping" ); assert.equal( el_bb.outerHeight( 129, true ).height(), expected + 5, "test border-box innerHeight(int, true) by roundtripping" );
equal( el.width( 101 ).width(), expected + 1, "test border-box width(int) by roundtripping" ); assert.equal( el.width( 101 ).width(), expected + 1, "test border-box width(int) by roundtripping" );
equal( el.innerWidth( 108 ).width(), expected + 2, "test border-box innerWidth(int) by roundtripping" ); assert.equal( el.innerWidth( 108 ).width(), expected + 2, "test border-box innerWidth(int) by roundtripping" );
equal( el.outerWidth( 117 ).width(), expected + 3, "test border-box outerWidth(int) by roundtripping" ); assert.equal( el.outerWidth( 117 ).width(), expected + 3, "test border-box outerWidth(int) by roundtripping" );
equal( el.outerWidth( 118, false ).width(), expected + 4, "test border-box outerWidth(int, false) by roundtripping" ); assert.equal( el.outerWidth( 118, false ).width(), expected + 4, "test border-box outerWidth(int, false) by roundtripping" );
equal( el.outerWidth( 129, true ).width(), expected + 5, "test border-box innerWidth(int, true) by roundtripping" ); assert.equal( el.outerWidth( 129, true ).width(), expected + 5, "test border-box innerWidth(int, true) by roundtripping" );
equal( el.height( 101 ).height(), expected + 1, "test border-box height(int) by roundtripping" ); assert.equal( el.height( 101 ).height(), expected + 1, "test border-box height(int) by roundtripping" );
equal( el.innerHeight( 108 ).height(), expected + 2, "test border-box innerHeight(int) by roundtripping" ); assert.equal( el.innerHeight( 108 ).height(), expected + 2, "test border-box innerHeight(int) by roundtripping" );
equal( el.outerHeight( 117 ).height(), expected + 3, "test border-box outerHeight(int) by roundtripping" ); assert.equal( el.outerHeight( 117 ).height(), expected + 3, "test border-box outerHeight(int) by roundtripping" );
equal( el.outerHeight( 118, false ).height(), expected + 4, "test border-box outerHeight(int, false) by roundtripping" ); assert.equal( el.outerHeight( 118, false ).height(), expected + 4, "test border-box outerHeight(int, false) by roundtripping" );
equal( el.outerHeight( 129, true ).height(), expected + 5, "test border-box innerHeight(int, true) by roundtripping" ); assert.equal( el.outerHeight( 129, true ).height(), expected + 5, "test border-box innerHeight(int, true) by roundtripping" );
}); });
testIframe( "dimensions/documentLarge", "window vs. large document", function( jQuery, window, document ) { testIframe(
expect(2); "dimensions/documentLarge",
"window vs. large document",
function( jQuery, window, document, assert ) {
assert.expect(2);
ok( jQuery( document ).height() > jQuery( window ).height(), "document height is larger than window height" ); assert.ok( jQuery( document ).height() > jQuery( window ).height(), "document height is larger than window height" );
ok( jQuery( document ).width() > jQuery( window ).width(), "document width is larger than window width" ); assert.ok( jQuery( document ).width() > jQuery( window ).width(), "document width is larger than window width" );
}); }
);
test( "allow modification of coordinates argument (gh-1848)", function() { QUnit.test( "allow modification of coordinates argument (gh-1848)", function( assert ) {
expect( 1 ); assert.expect( 1 );
var offsetTop, var offsetTop,
element = jQuery( "<div/>" ).appendTo( "#qunit-fixture" ); element = jQuery( "<div/>" ).appendTo( "#qunit-fixture" );
@ -475,7 +479,7 @@ test( "allow modification of coordinates argument (gh-1848)", function() {
}); });
offsetTop = element.offset().top; offsetTop = element.offset().top;
ok( Math.abs(offsetTop - 100) < 0.02, assert.ok( Math.abs(offsetTop - 100) < 0.02,
"coordinates are modified (got offset.top: " + offsetTop + ")"); "coordinates are modified (got offset.top: " + offsetTop + ")");
}); });

901
test/unit/effects.js vendored

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
module("exports", { teardown: moduleTeardown }); QUnit.module("exports", { teardown: moduleTeardown });
test("amdModule", function() { QUnit.test("amdModule", function( assert ) {
expect(1); assert.expect(1);
equal( jQuery, amdDefined, "Make sure defined module matches jQuery" ); assert.equal( jQuery, amdDefined, "Make sure defined module matches jQuery" );
}); });

File diff suppressed because it is too large Load Diff

View File

@ -22,7 +22,7 @@ var supportsScroll, supportsFixedPosition,
checkFixed.remove(); checkFixed.remove();
}; };
module("offset", { setup: function(){ QUnit.module("offset", { setup: function(){
if ( typeof checkSupport === "function" ) { if ( typeof checkSupport === "function" ) {
checkSupport(); checkSupport();
} }
@ -41,26 +41,26 @@ module("offset", { setup: function(){
the iframe window and the "jQuery" symbol is used to access any static methods. the iframe window and the "jQuery" symbol is used to access any static methods.
*/ */
test("empty set", function() { QUnit.test("empty set", function( assert ) {
expect( 2 ); assert.expect( 2 );
strictEqual( jQuery().offset(), undefined, "offset() returns undefined for empty set (#11962)" ); assert.strictEqual( jQuery().offset(), undefined, "offset() returns undefined for empty set (#11962)" );
strictEqual( jQuery().position(), undefined, "position() returns undefined for empty set (#11962)" ); assert.strictEqual( jQuery().position(), undefined, "position() returns undefined for empty set (#11962)" );
}); });
test("disconnected element", function() { QUnit.test("disconnected element", function( assert ) {
expect( 2 ); assert.expect( 2 );
var result = jQuery( document.createElement( "div" ) ).offset(); var result = jQuery( document.createElement( "div" ) ).offset();
// These tests are solely for master/compat consistency // These tests are solely for master/compat consistency
// Retrieving offset on disconnected/hidden elements is not officially // Retrieving offset on disconnected/hidden elements is not officially
// valid input, but will return zeros for back-compat // valid input, but will return zeros for back-compat
equal( result.top, 0, "Retrieving offset on disconnected elements returns zeros (gh-2310)" ); assert.equal( result.top, 0, "Retrieving offset on disconnected elements returns zeros (gh-2310)" );
equal( result.left, 0, "Retrieving offset on disconnected elements returns zeros (gh-2310)" ); assert.equal( result.left, 0, "Retrieving offset on disconnected elements returns zeros (gh-2310)" );
}); });
test("hidden (display: none) element", function() { QUnit.test("hidden (display: none) element", function( assert ) {
expect( 2 ); assert.expect( 2 );
var node = jQuery("<div style='display: none' />").appendTo("#qunit-fixture"), var node = jQuery("<div style='display: none' />").appendTo("#qunit-fixture"),
result = node.offset(); result = node.offset();
@ -70,12 +70,12 @@ test("hidden (display: none) element", function() {
// These tests are solely for master/compat consistency // These tests are solely for master/compat consistency
// Retrieving offset on disconnected/hidden elements is not officially // Retrieving offset on disconnected/hidden elements is not officially
// valid input, but will return zeros for back-compat // valid input, but will return zeros for back-compat
equal( result.top, 0, "Retrieving offset on hidden elements returns zeros (gh-2310)" ); assert.equal( result.top, 0, "Retrieving offset on hidden elements returns zeros (gh-2310)" );
equal( result.left, 0, "Retrieving offset on hidden elements returns zeros (gh-2310)" ); assert.equal( result.left, 0, "Retrieving offset on hidden elements returns zeros (gh-2310)" );
}); });
testIframe("offset/absolute", "absolute", function($, iframe) { testIframe("offset/absolute", "absolute", function( $, iframe, document, assert ) {
expect(4); assert.expect(4);
var doc = iframe.document, var doc = iframe.document,
tests; tests;
@ -85,8 +85,8 @@ testIframe("offset/absolute", "absolute", function($, iframe) {
{ "id": "#absolute-1", "top": 1, "left": 1 } { "id": "#absolute-1", "top": 1, "left": 1 }
]; ];
jQuery.each( tests, function() { jQuery.each( tests, function() {
equal( jQuery( this["id"], doc ).offset().top, this["top"], "jQuery('" + this["id"] + "').offset().top" ); assert.equal( jQuery( this["id"], doc ).offset().top, this["top"], "jQuery('" + this["id"] + "').offset().top" );
equal( jQuery( this["id"], doc ).offset().left, this["left"], "jQuery('" + this["id"] + "').offset().left" ); assert.equal( jQuery( this["id"], doc ).offset().left, this["left"], "jQuery('" + this["id"] + "').offset().left" );
}); });
@ -95,13 +95,13 @@ testIframe("offset/absolute", "absolute", function($, iframe) {
{ "id": "#absolute-1", "top": 0, "left": 0 } { "id": "#absolute-1", "top": 0, "left": 0 }
]; ];
jQuery.each( tests, function() { jQuery.each( tests, function() {
equal( jQuery( this["id"], doc ).position().top, this["top"], "jQuery('" + this["id"] + "').position().top" ); assert.equal( jQuery( this["id"], doc ).position().top, this["top"], "jQuery('" + this["id"] + "').position().top" );
equal( jQuery( this["id"], doc ).position().left, this["left"], "jQuery('" + this["id"] + "').position().left" ); assert.equal( jQuery( this["id"], doc ).position().left, this["left"], "jQuery('" + this["id"] + "').position().left" );
}); });
}); });
testIframe("offset/absolute", "absolute", function( $ ) { testIframe("offset/absolute", "absolute", function( $, window, document, assert ) {
expect(178); assert.expect(178);
var tests, offset; var tests, offset;
@ -113,8 +113,8 @@ testIframe("offset/absolute", "absolute", function( $ ) {
{ "id": "#absolute-2", "top": 20, "left": 20 } { "id": "#absolute-2", "top": 20, "left": 20 }
]; ];
jQuery.each( tests, function() { jQuery.each( tests, function() {
equal( $( this["id"] ).offset().top, this["top"], "jQuery('" + this["id"] + "').offset().top" ); assert.equal( $( this["id"] ).offset().top, this["top"], "jQuery('" + this["id"] + "').offset().top" );
equal( $( this["id"] ).offset().left, this["left"], "jQuery('" + this["id"] + "').offset().left" ); assert.equal( $( this["id"] ).offset().left, this["left"], "jQuery('" + this["id"] + "').offset().left" );
}); });
@ -126,14 +126,14 @@ testIframe("offset/absolute", "absolute", function( $ ) {
{ "id": "#absolute-2", "top": 19, "left": 19 } { "id": "#absolute-2", "top": 19, "left": 19 }
]; ];
jQuery.each( tests, function() { jQuery.each( tests, function() {
equal( $( this["id"] ).position().top, this["top"], "jQuery('" + this["id"] + "').position().top" ); assert.equal( $( this["id"] ).position().top, this["top"], "jQuery('" + this["id"] + "').position().top" );
equal( $( this["id"] ).position().left, this["left"], "jQuery('" + this["id"] + "').position().left" ); assert.equal( $( this["id"] ).position().left, this["left"], "jQuery('" + this["id"] + "').position().left" );
}); });
// test #5781 // test #5781
offset = $( "#positionTest" ).offset({ "top": 10, "left": 10 }).offset(); offset = $( "#positionTest" ).offset({ "top": 10, "left": 10 }).offset();
equal( offset.top, 10, "Setting offset on element with position absolute but 'auto' values." ); assert.equal( offset.top, 10, "Setting offset on element with position absolute but 'auto' values." );
equal( offset.left, 10, "Setting offset on element with position absolute but 'auto' values." ); assert.equal( offset.left, 10, "Setting offset on element with position absolute but 'auto' values." );
// set offset // set offset
@ -157,24 +157,24 @@ testIframe("offset/absolute", "absolute", function( $ ) {
]; ];
jQuery.each( tests, function() { jQuery.each( tests, function() {
$( this["id"] ).offset({ "top": this["top"], "left": this["left"] }); $( this["id"] ).offset({ "top": this["top"], "left": this["left"] });
equal( $( this["id"] ).offset().top, this["top"], "jQuery('" + this["id"] + "').offset({ top: " + this["top"] + " })" ); assert.equal( $( this["id"] ).offset().top, this["top"], "jQuery('" + this["id"] + "').offset({ top: " + this["top"] + " })" );
equal( $( this["id"] ).offset().left, this["left"], "jQuery('" + this["id"] + "').offset({ left: " + this["left"] + " })" ); assert.equal( $( this["id"] ).offset().left, this["left"], "jQuery('" + this["id"] + "').offset({ left: " + this["left"] + " })" );
var top = this["top"], left = this["left"]; var top = this["top"], left = this["left"];
$( this["id"] ).offset(function(i, val){ $( this["id"] ).offset(function(i, val){
equal( val.top, top, "Verify incoming top position." ); assert.equal( val.top, top, "Verify incoming top position." );
equal( val.left, left, "Verify incoming top position." ); assert.equal( val.left, left, "Verify incoming top position." );
return { "top": top + 1, "left": left + 1 }; return { "top": top + 1, "left": left + 1 };
}); });
equal( $( this["id"] ).offset().top, this["top"] + 1, "jQuery('" + this["id"] + "').offset({ top: " + (this["top"] + 1) + " })" ); assert.equal( $( this["id"] ).offset().top, this["top"] + 1, "jQuery('" + this["id"] + "').offset({ top: " + (this["top"] + 1) + " })" );
equal( $( this["id"] ).offset().left, this["left"] + 1, "jQuery('" + this["id"] + "').offset({ left: " + (this["left"] + 1) + " })" ); assert.equal( $( this["id"] ).offset().left, this["left"] + 1, "jQuery('" + this["id"] + "').offset({ left: " + (this["left"] + 1) + " })" );
$( this["id"] ) $( this["id"] )
.offset({ "left": this["left"] + 2 }) .offset({ "left": this["left"] + 2 })
.offset({ "top": this["top"] + 2 }); .offset({ "top": this["top"] + 2 });
equal( $( this["id"] ).offset().top, this["top"] + 2, "Setting one property at a time." ); assert.equal( $( this["id"] ).offset().top, this["top"] + 2, "Setting one property at a time." );
equal( $( this["id"] ).offset().left, this["left"] + 2, "Setting one property at a time." ); assert.equal( $( this["id"] ).offset().left, this["left"] + 2, "Setting one property at a time." );
$( this["id"] ).offset({ "top": this["top"], "left": this["left"], "using": function( props ) { $( this["id"] ).offset({ "top": this["top"], "left": this["left"], "using": function( props ) {
$( this ).css({ $( this ).css({
@ -182,13 +182,13 @@ testIframe("offset/absolute", "absolute", function( $ ) {
"left": props.left + 1 "left": props.left + 1
}); });
}}); }});
equal( $( this["id"] ).offset().top, this["top"] + 1, "jQuery('" + this["id"] + "').offset({ top: " + (this["top"] + 1) + ", using: fn })" ); assert.equal( $( this["id"] ).offset().top, this["top"] + 1, "jQuery('" + this["id"] + "').offset({ top: " + (this["top"] + 1) + ", using: fn })" );
equal( $( this["id"] ).offset().left, this["left"] + 1, "jQuery('" + this["id"] + "').offset({ left: " + (this["left"] + 1) + ", using: fn })" ); assert.equal( $( this["id"] ).offset().left, this["left"] + 1, "jQuery('" + this["id"] + "').offset({ left: " + (this["left"] + 1) + ", using: fn })" );
}); });
}); });
testIframe("offset/relative", "relative", function( $ ) { testIframe("offset/relative", "relative", function( $, window, document, assert ) {
expect(60); assert.expect(60);
// get offset // get offset
var tests = [ var tests = [
@ -197,8 +197,8 @@ testIframe("offset/relative", "relative", function( $ ) {
{ "id": "#relative-2", "top": 142, "left": 27 } { "id": "#relative-2", "top": 142, "left": 27 }
]; ];
jQuery.each( tests, function() { jQuery.each( tests, function() {
equal( $( this["id"] ).offset().top, this["top"], "jQuery('" + this["id"] + "').offset().top" ); assert.equal( $( this["id"] ).offset().top, this["top"], "jQuery('" + this["id"] + "').offset().top" );
equal( $( this["id"] ).offset().left, this["left"], "jQuery('" + this["id"] + "').offset().left" ); assert.equal( $( this["id"] ).offset().left, this["left"], "jQuery('" + this["id"] + "').offset().left" );
}); });
@ -209,8 +209,8 @@ testIframe("offset/relative", "relative", function( $ ) {
{ "id": "#relative-2", "top": 141, "left": 26 } { "id": "#relative-2", "top": 141, "left": 26 }
]; ];
jQuery.each( tests, function() { jQuery.each( tests, function() {
equal( $( this["id"] ).position().top, this["top"], "jQuery('" + this["id"] + "').position().top" ); assert.equal( $( this["id"] ).position().top, this["top"], "jQuery('" + this["id"] + "').position().top" );
equal( $( this["id"] ).position().left, this["left"], "jQuery('" + this["id"] + "').position().left" ); assert.equal( $( this["id"] ).position().left, this["left"], "jQuery('" + this["id"] + "').position().left" );
}); });
@ -231,8 +231,8 @@ testIframe("offset/relative", "relative", function( $ ) {
]; ];
jQuery.each( tests, function() { jQuery.each( tests, function() {
$( this["id"] ).offset({ "top": this["top"], "left": this["left"] }); $( this["id"] ).offset({ "top": this["top"], "left": this["left"] });
equal( $( this["id"] ).offset().top, this["top"], "jQuery('" + this["id"] + "').offset({ top: " + this["top"] + " })" ); assert.equal( $( this["id"] ).offset().top, this["top"], "jQuery('" + this["id"] + "').offset({ top: " + this["top"] + " })" );
equal( $( this["id"] ).offset().left, this["left"], "jQuery('" + this["id"] + "').offset({ left: " + this["left"] + " })" ); assert.equal( $( this["id"] ).offset().left, this["left"], "jQuery('" + this["id"] + "').offset({ left: " + this["left"] + " })" );
$( this["id"] ).offset({ "top": this["top"], "left": this["left"], "using": function( props ) { $( this["id"] ).offset({ "top": this["top"], "left": this["left"], "using": function( props ) {
$( this ).css({ $( this ).css({
@ -240,13 +240,13 @@ testIframe("offset/relative", "relative", function( $ ) {
"left": props.left + 1 "left": props.left + 1
}); });
}}); }});
equal( $( this["id"] ).offset().top, this["top"] + 1, "jQuery('" + this["id"] + "').offset({ top: " + (this["top"] + 1) + ", using: fn })" ); assert.equal( $( this["id"] ).offset().top, this["top"] + 1, "jQuery('" + this["id"] + "').offset({ top: " + (this["top"] + 1) + ", using: fn })" );
equal( $( this["id"] ).offset().left, this["left"] + 1, "jQuery('" + this["id"] + "').offset({ left: " + (this["left"] + 1) + ", using: fn })" ); assert.equal( $( this["id"] ).offset().left, this["left"] + 1, "jQuery('" + this["id"] + "').offset({ left: " + (this["left"] + 1) + ", using: fn })" );
}); });
}); });
testIframe("offset/static", "static", function( $ ) { testIframe("offset/static", "static", function( $, window, document, assert ) {
expect( 80 ); assert.expect( 80 );
// get offset // get offset
var tests = [ var tests = [
@ -256,8 +256,8 @@ testIframe("offset/static", "static", function( $ ) {
{ "id": "#static-2", "top": 122, left: 7 } { "id": "#static-2", "top": 122, left: 7 }
]; ];
jQuery.each( tests, function() { jQuery.each( tests, function() {
equal( $( this["id"] ).offset().top, this["top"], "jQuery('" + this["id"] + "').offset().top" ); assert.equal( $( this["id"] ).offset().top, this["top"], "jQuery('" + this["id"] + "').offset().top" );
equal( $( this["id"] ).offset().left, this["left"], "jQuery('" + this["id"] + "').offset().left" ); assert.equal( $( this["id"] ).offset().left, this["left"], "jQuery('" + this["id"] + "').offset().left" );
}); });
@ -269,8 +269,8 @@ testIframe("offset/static", "static", function( $ ) {
{ "id": "#static-2", "top": 121, "left": 6 } { "id": "#static-2", "top": 121, "left": 6 }
]; ];
jQuery.each( tests, function() { jQuery.each( tests, function() {
equal( $( this["id"] ).position().top, this["top"], "jQuery('" + this["top"] + "').position().top" ); assert.equal( $( this["id"] ).position().top, this["top"], "jQuery('" + this["top"] + "').position().top" );
equal( $( this["id"] ).position().left, this["left"], "jQuery('" + this["left"] +"').position().left" ); assert.equal( $( this["id"] ).position().left, this["left"], "jQuery('" + this["left"] +"').position().left" );
}); });
@ -295,8 +295,8 @@ testIframe("offset/static", "static", function( $ ) {
]; ];
jQuery.each( tests, function() { jQuery.each( tests, function() {
$( this["id"] ).offset({ "top": this["top"], "left": this["left"] }); $( this["id"] ).offset({ "top": this["top"], "left": this["left"] });
equal( $( this["id"] ).offset().top, this["top"], "jQuery('" + this["id"] + "').offset({ top: " + this["top"] + " })" ); assert.equal( $( this["id"] ).offset().top, this["top"], "jQuery('" + this["id"] + "').offset({ top: " + this["top"] + " })" );
equal( $( this["id"] ).offset().left, this["left"], "jQuery('" + this["id"] + "').offset({ left: " + this["left"] + " })" ); assert.equal( $( this["id"] ).offset().left, this["left"], "jQuery('" + this["id"] + "').offset({ left: " + this["left"] + " })" );
$( this["id"] ).offset({ "top": this["top"], "left": this["left"], "using": function( props ) { $( this["id"] ).offset({ "top": this["top"], "left": this["left"], "using": function( props ) {
$( this ).css({ $( this ).css({
@ -304,13 +304,13 @@ testIframe("offset/static", "static", function( $ ) {
"left": props.left + 1 "left": props.left + 1
}); });
}}); }});
equal( $( this["id"] ).offset().top, this["top"] + 1, "jQuery('" + this["id"] + "').offset({ top: " + (this["top"] + 1) + ", using: fn })" ); assert.equal( $( this["id"] ).offset().top, this["top"] + 1, "jQuery('" + this["id"] + "').offset({ top: " + (this["top"] + 1) + ", using: fn })" );
equal( $( this["id"] ).offset().left, this["left"] + 1, "jQuery('" + this["id"] + "').offset({ left: " + (this["left"] + 1) + ", using: fn })" ); assert.equal( $( this["id"] ).offset().left, this["left"] + 1, "jQuery('" + this["id"] + "').offset({ left: " + (this["left"] + 1) + ", using: fn })" );
}); });
}); });
testIframe("offset/fixed", "fixed", function( $ ) { testIframe("offset/fixed", "fixed", function( $, window, document, assert ) {
expect(34); assert.expect(34);
var tests, $noTopLeft; var tests, $noTopLeft;
@ -333,22 +333,22 @@ testIframe("offset/fixed", "fixed", function( $ ) {
jQuery.each( tests, function() { jQuery.each( tests, function() {
if ( !window.supportsScroll ) { if ( !window.supportsScroll ) {
ok( true, "Browser doesn't support scroll position." ); assert.ok( true, "Browser doesn't support scroll position." );
ok( true, "Browser doesn't support scroll position." ); assert.ok( true, "Browser doesn't support scroll position." );
ok( true, "Browser doesn't support scroll position." ); assert.ok( true, "Browser doesn't support scroll position." );
ok( true, "Browser doesn't support scroll position." ); assert.ok( true, "Browser doesn't support scroll position." );
} else if ( window.supportsFixedPosition ) { } else if ( window.supportsFixedPosition ) {
equal( $( this["id"] ).offset().top, this["offsetTop"], "jQuery('" + this["id"] + "').offset().top" ); assert.equal( $( this["id"] ).offset().top, this["offsetTop"], "jQuery('" + this["id"] + "').offset().top" );
equal( $( this["id"] ).position().top, this["positionTop"], "jQuery('" + this["id"] + "').position().top" ); assert.equal( $( this["id"] ).position().top, this["positionTop"], "jQuery('" + this["id"] + "').position().top" );
equal( $( this["id"] ).offset().left, this["offsetLeft"], "jQuery('" + this["id"] + "').offset().left" ); assert.equal( $( this["id"] ).offset().left, this["offsetLeft"], "jQuery('" + this["id"] + "').offset().left" );
equal( $( this["id"] ).position().left, this["positionLeft"], "jQuery('" + this["id"] + "').position().left" ); assert.equal( $( this["id"] ).position().left, this["positionLeft"], "jQuery('" + this["id"] + "').position().left" );
} else { } else {
// need to have same number of assertions // need to have same number of assertions
ok( true, "Fixed position is not supported" ); assert.ok( true, "Fixed position is not supported" );
ok( true, "Fixed position is not supported" ); assert.ok( true, "Fixed position is not supported" );
ok( true, "Fixed position is not supported" ); assert.ok( true, "Fixed position is not supported" );
ok( true, "Fixed position is not supported" ); assert.ok( true, "Fixed position is not supported" );
} }
}); });
@ -364,8 +364,8 @@ testIframe("offset/fixed", "fixed", function( $ ) {
jQuery.each( tests, function() { jQuery.each( tests, function() {
if ( window.supportsFixedPosition ) { if ( window.supportsFixedPosition ) {
$( this["id"] ).offset({ "top": this["top"], "left": this["left"] }); $( this["id"] ).offset({ "top": this["top"], "left": this["left"] });
equal( $( this["id"] ).offset().top, this["top"], "jQuery('" + this["id"] + "').offset({ top: " + this["top"] + " })" ); assert.equal( $( this["id"] ).offset().top, this["top"], "jQuery('" + this["id"] + "').offset({ top: " + this["top"] + " })" );
equal( $( this["id"] ).offset().left, this["left"], "jQuery('" + this["id"] + "').offset({ left: " + this["left"] + " })" ); assert.equal( $( this["id"] ).offset().left, this["left"], "jQuery('" + this["id"] + "').offset({ left: " + this["left"] + " })" );
$( this["id"] ).offset({ "top": this["top"], "left": this["left"], "using": function( props ) { $( this["id"] ).offset({ "top": this["top"], "left": this["left"], "using": function( props ) {
$( this ).css({ $( this ).css({
@ -373,165 +373,165 @@ testIframe("offset/fixed", "fixed", function( $ ) {
"left": props.left + 1 "left": props.left + 1
}); });
}}); }});
equal( $( this["id"] ).offset().top, this["top"] + 1, "jQuery('" + this["id"] + "').offset({ top: " + (this["top"] + 1) + ", using: fn })" ); assert.equal( $( this["id"] ).offset().top, this["top"] + 1, "jQuery('" + this["id"] + "').offset({ top: " + (this["top"] + 1) + ", using: fn })" );
equal( $( this["id"] ).offset().left, this["left"] + 1, "jQuery('" + this["id"] + "').offset({ left: " + (this["left"] + 1) + ", using: fn })" ); assert.equal( $( this["id"] ).offset().left, this["left"] + 1, "jQuery('" + this["id"] + "').offset({ left: " + (this["left"] + 1) + ", using: fn })" );
} else { } else {
// need to have same number of assertions // need to have same number of assertions
ok( true, "Fixed position is not supported" ); assert.ok( true, "Fixed position is not supported" );
ok( true, "Fixed position is not supported" ); assert.ok( true, "Fixed position is not supported" );
ok( true, "Fixed position is not supported" ); assert.ok( true, "Fixed position is not supported" );
ok( true, "Fixed position is not supported" ); assert.ok( true, "Fixed position is not supported" );
} }
}); });
// Bug 8316 // Bug 8316
$noTopLeft = $("#fixed-no-top-left"); $noTopLeft = $("#fixed-no-top-left");
if ( window.supportsFixedPosition ) { if ( window.supportsFixedPosition ) {
equal( $noTopLeft.offset().top, 1007, "Check offset top for fixed element with no top set" ); assert.equal( $noTopLeft.offset().top, 1007, "Check offset top for fixed element with no top set" );
equal( $noTopLeft.offset().left, 1007, "Check offset left for fixed element with no left set" ); assert.equal( $noTopLeft.offset().left, 1007, "Check offset left for fixed element with no left set" );
} else { } else {
// need to have same number of assertions // need to have same number of assertions
ok( true, "Fixed position is not supported" ); assert.ok( true, "Fixed position is not supported" );
ok( true, "Fixed position is not supported" ); assert.ok( true, "Fixed position is not supported" );
} }
}); });
testIframe("offset/table", "table", function( $ ) { testIframe("offset/table", "table", function( $, window, document, assert ) {
expect(4); assert.expect(4);
equal( $("#table-1").offset().top, 6, "jQuery('#table-1').offset().top" ); assert.equal( $("#table-1").offset().top, 6, "jQuery('#table-1').offset().top" );
equal( $("#table-1").offset().left, 6, "jQuery('#table-1').offset().left" ); assert.equal( $("#table-1").offset().left, 6, "jQuery('#table-1').offset().left" );
equal( $("#th-1").offset().top, 10, "jQuery('#th-1').offset().top" ); assert.equal( $("#th-1").offset().top, 10, "jQuery('#th-1').offset().top" );
equal( $("#th-1").offset().left, 10, "jQuery('#th-1').offset().left" ); assert.equal( $("#th-1").offset().left, 10, "jQuery('#th-1').offset().left" );
}); });
testIframe("offset/scroll", "scroll", function( $, win ) { testIframe("offset/scroll", "scroll", function( $, win, doc, assert ) {
expect( 30 ); assert.expect( 30 );
equal( $("#scroll-1").offset().top, 7, "jQuery('#scroll-1').offset().top" ); assert.equal( $("#scroll-1").offset().top, 7, "jQuery('#scroll-1').offset().top" );
equal( $("#scroll-1").offset().left, 7, "jQuery('#scroll-1').offset().left" ); assert.equal( $("#scroll-1").offset().left, 7, "jQuery('#scroll-1').offset().left" );
equal( $("#scroll-1-1").offset().top, 11, "jQuery('#scroll-1-1').offset().top" ); assert.equal( $("#scroll-1-1").offset().top, 11, "jQuery('#scroll-1-1').offset().top" );
equal( $("#scroll-1-1").offset().left, 11, "jQuery('#scroll-1-1').offset().left" ); assert.equal( $("#scroll-1-1").offset().left, 11, "jQuery('#scroll-1-1').offset().left" );
// These tests are solely for master/compat consistency // These tests are solely for master/compat consistency
// Retrieving offset on disconnected/hidden elements is not officially // Retrieving offset on disconnected/hidden elements is not officially
// valid input, but will return zeros for back-compat // valid input, but will return zeros for back-compat
equal( $("#hidden").offset().top, 0, "Hidden elements do not subtract scroll" ); assert.equal( $("#hidden").offset().top, 0, "Hidden elements do not subtract scroll" );
equal( $("#hidden").offset().left, 0, "Hidden elements do not subtract scroll" ); assert.equal( $("#hidden").offset().left, 0, "Hidden elements do not subtract scroll" );
// scroll offset tests .scrollTop/Left // scroll offset tests .scrollTop/Left
equal( $("#scroll-1").scrollTop(), 5, "jQuery('#scroll-1').scrollTop()" ); assert.equal( $("#scroll-1").scrollTop(), 5, "jQuery('#scroll-1').scrollTop()" );
equal( $("#scroll-1").scrollLeft(), 5, "jQuery('#scroll-1').scrollLeft()" ); assert.equal( $("#scroll-1").scrollLeft(), 5, "jQuery('#scroll-1').scrollLeft()" );
equal( $("#scroll-1-1").scrollTop(), 0, "jQuery('#scroll-1-1').scrollTop()" ); assert.equal( $("#scroll-1-1").scrollTop(), 0, "jQuery('#scroll-1-1').scrollTop()" );
equal( $("#scroll-1-1").scrollLeft(), 0, "jQuery('#scroll-1-1').scrollLeft()" ); assert.equal( $("#scroll-1-1").scrollLeft(), 0, "jQuery('#scroll-1-1').scrollLeft()" );
// scroll method chaining // scroll method chaining
equal( $("#scroll-1").scrollTop(undefined).scrollTop(), 5, ".scrollTop(undefined) is chainable (#5571)" ); assert.equal( $("#scroll-1").scrollTop(undefined).scrollTop(), 5, ".scrollTop(undefined) is chainable (#5571)" );
equal( $("#scroll-1").scrollLeft(undefined).scrollLeft(), 5, ".scrollLeft(undefined) is chainable (#5571)" ); assert.equal( $("#scroll-1").scrollLeft(undefined).scrollLeft(), 5, ".scrollLeft(undefined) is chainable (#5571)" );
win.name = "test"; win.name = "test";
if ( !window.supportsScroll ) { if ( !window.supportsScroll ) {
ok( true, "Browser doesn't support scroll position." ); assert.ok( true, "Browser doesn't support scroll position." );
ok( true, "Browser doesn't support scroll position." ); assert.ok( true, "Browser doesn't support scroll position." );
ok( true, "Browser doesn't support scroll position." ); assert.ok( true, "Browser doesn't support scroll position." );
ok( true, "Browser doesn't support scroll position." ); assert.ok( true, "Browser doesn't support scroll position." );
} else { } else {
equal( $(win).scrollTop(), 1000, "jQuery(window).scrollTop()" ); assert.equal( $(win).scrollTop(), 1000, "jQuery(window).scrollTop()" );
equal( $(win).scrollLeft(), 1000, "jQuery(window).scrollLeft()" ); assert.equal( $(win).scrollLeft(), 1000, "jQuery(window).scrollLeft()" );
equal( $(win.document).scrollTop(), 1000, "jQuery(document).scrollTop()" ); assert.equal( $(win.document).scrollTop(), 1000, "jQuery(document).scrollTop()" );
equal( $(win.document).scrollLeft(), 1000, "jQuery(document).scrollLeft()" ); assert.equal( $(win.document).scrollLeft(), 1000, "jQuery(document).scrollLeft()" );
} }
// test jQuery using parent window/document // test jQuery using parent window/document
// jQuery reference here is in the iframe // jQuery reference here is in the iframe
window.scrollTo(0,0); window.scrollTo(0,0);
equal( $(window).scrollTop(), 0, "jQuery(window).scrollTop() other window" ); assert.equal( $(window).scrollTop(), 0, "jQuery(window).scrollTop() other window" );
equal( $(window).scrollLeft(), 0, "jQuery(window).scrollLeft() other window" ); assert.equal( $(window).scrollLeft(), 0, "jQuery(window).scrollLeft() other window" );
equal( $(document).scrollTop(), 0, "jQuery(window).scrollTop() other document" ); assert.equal( $(document).scrollTop(), 0, "jQuery(window).scrollTop() other document" );
equal( $(document).scrollLeft(), 0, "jQuery(window).scrollLeft() other document" ); assert.equal( $(document).scrollLeft(), 0, "jQuery(window).scrollLeft() other document" );
// Tests scrollTop/Left with empty jquery objects // Tests scrollTop/Left with empty jquery objects
notEqual( $().scrollTop(100), null, "jQuery().scrollTop(100) testing setter on empty jquery object" ); assert.notEqual( $().scrollTop(100), null, "jQuery().scrollTop(100) testing setter on empty jquery object" );
notEqual( $().scrollLeft(100), null, "jQuery().scrollLeft(100) testing setter on empty jquery object" ); assert.notEqual( $().scrollLeft(100), null, "jQuery().scrollLeft(100) testing setter on empty jquery object" );
notEqual( $().scrollTop(null), null, "jQuery().scrollTop(null) testing setter on empty jquery object" ); assert.notEqual( $().scrollTop(null), null, "jQuery().scrollTop(null) testing setter on empty jquery object" );
notEqual( $().scrollLeft(null), null, "jQuery().scrollLeft(null) testing setter on empty jquery object" ); assert.notEqual( $().scrollLeft(null), null, "jQuery().scrollLeft(null) testing setter on empty jquery object" );
strictEqual( $().scrollTop(), null, "jQuery().scrollTop(100) testing setter on empty jquery object" ); assert.strictEqual( $().scrollTop(), null, "jQuery().scrollTop(100) testing setter on empty jquery object" );
strictEqual( $().scrollLeft(), null, "jQuery().scrollLeft(100) testing setter on empty jquery object" ); assert.strictEqual( $().scrollLeft(), null, "jQuery().scrollLeft(100) testing setter on empty jquery object" );
// Tests position after parent scrolling (#15239) // Tests position after parent scrolling (#15239)
$("#scroll-1").scrollTop(0); $("#scroll-1").scrollTop(0);
$("#scroll-1").scrollLeft(0); $("#scroll-1").scrollLeft(0);
equal( $("#scroll-1-1").position().top, 6, "jQuery('#scroll-1-1').position().top unaffected by parent scrolling" ); assert.equal( $("#scroll-1-1").position().top, 6, "jQuery('#scroll-1-1').position().top unaffected by parent scrolling" );
equal( $("#scroll-1-1").position().left, 6, "jQuery('#scroll-1-1').position().left unaffected by parent scrolling" ); assert.equal( $("#scroll-1-1").position().left, 6, "jQuery('#scroll-1-1').position().left unaffected by parent scrolling" );
$("#scroll-1").scrollTop(5); $("#scroll-1").scrollTop(5);
$("#scroll-1").scrollLeft(5); $("#scroll-1").scrollLeft(5);
equal( $("#scroll-1-1").position().top, 6, "jQuery('#scroll-1-1').position().top unaffected by parent scrolling" ); assert.equal( $("#scroll-1-1").position().top, 6, "jQuery('#scroll-1-1').position().top unaffected by parent scrolling" );
equal( $("#scroll-1-1").position().left, 6, "jQuery('#scroll-1-1').position().left unaffected by parent scrolling" ); assert.equal( $("#scroll-1-1").position().left, 6, "jQuery('#scroll-1-1').position().left unaffected by parent scrolling" );
}); });
testIframe("offset/body", "body", function( $ ) { testIframe("offset/body", "body", function( $, window, document, assert ) {
expect(4); assert.expect(4);
equal( $("body").offset().top, 1, "jQuery('#body').offset().top" ); assert.equal( $("body").offset().top, 1, "jQuery('#body').offset().top" );
equal( $("body").offset().left, 1, "jQuery('#body').offset().left" ); assert.equal( $("body").offset().left, 1, "jQuery('#body').offset().left" );
equal( $("#firstElement").position().left, 5, "$('#firstElement').position().left" ); assert.equal( $("#firstElement").position().left, 5, "$('#firstElement').position().left" );
equal( $("#firstElement").position().top, 5, "$('#firstElement').position().top" ); assert.equal( $("#firstElement").position().top, 5, "$('#firstElement').position().top" );
}); });
test("chaining", function() { QUnit.test("chaining", function( assert ) {
expect(3); assert.expect(3);
var coords = { "top": 1, "left": 1 }; var coords = { "top": 1, "left": 1 };
equal( jQuery("#absolute-1").offset(coords).jquery, jQuery.fn.jquery, "offset(coords) returns jQuery object" ); assert.equal( jQuery("#absolute-1").offset(coords).jquery, jQuery.fn.jquery, "offset(coords) returns jQuery object" );
equal( jQuery("#non-existent").offset(coords).jquery, jQuery.fn.jquery, "offset(coords) with empty jQuery set returns jQuery object" ); assert.equal( jQuery("#non-existent").offset(coords).jquery, jQuery.fn.jquery, "offset(coords) with empty jQuery set returns jQuery object" );
equal( jQuery("#absolute-1").offset(undefined).jquery, jQuery.fn.jquery, "offset(undefined) returns jQuery object (#5571)" ); assert.equal( jQuery("#absolute-1").offset(undefined).jquery, jQuery.fn.jquery, "offset(undefined) returns jQuery object (#5571)" );
}); });
test("offsetParent", function(){ QUnit.test("offsetParent", function( assert ){
expect(13); assert.expect(13);
var body, header, div, area; var body, header, div, area;
body = jQuery("body").offsetParent(); body = jQuery("body").offsetParent();
equal( body.length, 1, "Only one offsetParent found." ); assert.equal( body.length, 1, "Only one offsetParent found." );
equal( body[0], document.documentElement, "The html element is the offsetParent of the body." ); assert.equal( body[0], document.documentElement, "The html element is the offsetParent of the body." );
header = jQuery("#qunit").offsetParent(); header = jQuery("#qunit").offsetParent();
equal( header.length, 1, "Only one offsetParent found." ); assert.equal( header.length, 1, "Only one offsetParent found." );
equal( header[0], document.documentElement, "The html element is the offsetParent of #qunit." ); assert.equal( header[0], document.documentElement, "The html element is the offsetParent of #qunit." );
div = jQuery("#nothiddendivchild").offsetParent(); div = jQuery("#nothiddendivchild").offsetParent();
equal( div.length, 1, "Only one offsetParent found." ); assert.equal( div.length, 1, "Only one offsetParent found." );
equal( div[0], document.getElementById("qunit-fixture"), "The #qunit-fixture is the offsetParent of #nothiddendivchild." ); assert.equal( div[0], document.getElementById("qunit-fixture"), "The #qunit-fixture is the offsetParent of #nothiddendivchild." );
jQuery("#nothiddendiv").css("position", "relative"); jQuery("#nothiddendiv").css("position", "relative");
div = jQuery("#nothiddendivchild").offsetParent(); div = jQuery("#nothiddendivchild").offsetParent();
equal( div.length, 1, "Only one offsetParent found." ); assert.equal( div.length, 1, "Only one offsetParent found." );
equal( div[0], jQuery("#nothiddendiv")[0], "The div is the offsetParent." ); assert.equal( div[0], jQuery("#nothiddendiv")[0], "The div is the offsetParent." );
div = jQuery("body, #nothiddendivchild").offsetParent(); div = jQuery("body, #nothiddendivchild").offsetParent();
equal( div.length, 2, "Two offsetParent found." ); assert.equal( div.length, 2, "Two offsetParent found." );
equal( div[0], document.documentElement, "The html element is the offsetParent of the body." ); assert.equal( div[0], document.documentElement, "The html element is the offsetParent of the body." );
equal( div[1], jQuery("#nothiddendiv")[0], "The div is the offsetParent." ); assert.equal( div[1], jQuery("#nothiddendiv")[0], "The div is the offsetParent." );
area = jQuery("#imgmap area").offsetParent(); area = jQuery("#imgmap area").offsetParent();
equal( area[0], document.documentElement, "The html element is the offsetParent of the body." ); assert.equal( area[0], document.documentElement, "The html element is the offsetParent of the body." );
div = jQuery("<div>").css({ "position": "absolute" }).appendTo("body"); div = jQuery("<div>").css({ "position": "absolute" }).appendTo("body");
equal( div.offsetParent()[0], document.documentElement, "Absolutely positioned div returns html as offset parent, see #12139" ); assert.equal( div.offsetParent()[0], document.documentElement, "Absolutely positioned div returns html as offset parent, see #12139" );
div.remove(); div.remove();
}); });
test("fractions (see #7730 and #7885)", function() { QUnit.test("fractions (see #7730 and #7885)", function( assert ) {
expect(2); assert.expect(2);
jQuery("body").append("<div id='fractions'/>"); jQuery("body").append("<div id='fractions'/>");
@ -551,14 +551,14 @@ test("fractions (see #7730 and #7885)", function() {
result = div.offset(); result = div.offset();
equal( result.top, expected.top, "Check top" ); assert.equal( result.top, expected.top, "Check top" );
equal( result.left, expected.left, "Check left" ); assert.equal( result.left, expected.left, "Check left" );
div.remove(); div.remove();
}); });
test("iframe scrollTop/Left (see gh-1945)", function() { QUnit.test("iframe scrollTop/Left (see gh-1945)", function( assert ) {
expect( 2 ); assert.expect( 2 );
var ifDoc = jQuery( "#iframe" )[ 0 ].contentDocument; var ifDoc = jQuery( "#iframe" )[ 0 ].contentDocument;
@ -568,8 +568,8 @@ test("iframe scrollTop/Left (see gh-1945)", function() {
if ( /iphone os/i.test( navigator.userAgent ) || if ( /iphone os/i.test( navigator.userAgent ) ||
/android 2\.3/i.test( navigator.userAgent ) || /android 2\.3/i.test( navigator.userAgent ) ||
/android 4\.0/i.test( navigator.userAgent ) ) { /android 4\.0/i.test( navigator.userAgent ) ) {
equal( true, true, "Can't scroll iframes in this environment" ); assert.equal( true, true, "Can't scroll iframes in this environment" );
equal( true, true, "Can't scroll iframes in this environment" ); assert.equal( true, true, "Can't scroll iframes in this environment" );
} else { } else {
// Tests scrollTop/Left with iframes // Tests scrollTop/Left with iframes
@ -579,8 +579,8 @@ test("iframe scrollTop/Left (see gh-1945)", function() {
jQuery( ifDoc ).scrollTop( 200 ); jQuery( ifDoc ).scrollTop( 200 );
jQuery( ifDoc ).scrollLeft( 500 ); jQuery( ifDoc ).scrollLeft( 500 );
equal( jQuery( ifDoc ).scrollTop(), 200, "$($('#iframe')[0].contentDocument).scrollTop()" ); assert.equal( jQuery( ifDoc ).scrollTop(), 200, "$($('#iframe')[0].contentDocument).scrollTop()" );
equal( jQuery( ifDoc ).scrollLeft(), 500, "$($('#iframe')[0].contentDocument).scrollLeft()" ); assert.equal( jQuery( ifDoc ).scrollLeft(), 500, "$($('#iframe')[0].contentDocument).scrollLeft()" );
} }
}); });

View File

@ -1,155 +1,155 @@
module( "queue", { teardown: moduleTeardown }); QUnit.module( "queue", { teardown: moduleTeardown });
test( "queue() with other types", function() { QUnit.test( "queue() with other types", function( assert ) {
expect( 14 ); assert.expect( 14 );
stop(); QUnit.stop();
var $div = jQuery({}), var $div = jQuery({}),
counter = 0; counter = 0;
$div.promise( "foo" ).done(function() { $div.promise( "foo" ).done(function() {
equal( counter, 0, "Deferred for collection with no queue is automatically resolved" ); assert.equal( counter, 0, "Deferred for collection with no queue is automatically resolved" );
}); });
$div $div
.queue("foo",function(){ .queue("foo",function(){
equal( ++counter, 1, "Dequeuing" ); assert.equal( ++counter, 1, "Dequeuing" );
jQuery.dequeue(this,"foo"); jQuery.dequeue(this,"foo");
}) })
.queue("foo",function(){ .queue("foo",function(){
equal( ++counter, 2, "Dequeuing" ); assert.equal( ++counter, 2, "Dequeuing" );
jQuery(this).dequeue("foo"); jQuery(this).dequeue("foo");
}) })
.queue("foo",function(){ .queue("foo",function(){
equal( ++counter, 3, "Dequeuing" ); assert.equal( ++counter, 3, "Dequeuing" );
}) })
.queue("foo",function(){ .queue("foo",function(){
equal( ++counter, 4, "Dequeuing" ); assert.equal( ++counter, 4, "Dequeuing" );
}); });
$div.promise("foo").done(function() { $div.promise("foo").done(function() {
equal( counter, 4, "Testing previous call to dequeue in deferred" ); assert.equal( counter, 4, "Testing previous call to dequeue in deferred" );
start(); QUnit.start();
}); });
equal( $div.queue("foo").length, 4, "Testing queue length" ); assert.equal( $div.queue("foo").length, 4, "Testing queue length" );
equal( $div.queue("foo", undefined).queue("foo").length, 4, ".queue('name',undefined) does nothing but is chainable (#5571)"); assert.equal( $div.queue("foo", undefined).queue("foo").length, 4, ".queue('name',undefined) does nothing but is chainable (#5571)");
$div.dequeue("foo"); $div.dequeue("foo");
equal( counter, 3, "Testing previous call to dequeue" ); assert.equal( counter, 3, "Testing previous call to dequeue" );
equal( $div.queue("foo").length, 1, "Testing queue length" ); assert.equal( $div.queue("foo").length, 1, "Testing queue length" );
$div.dequeue("foo"); $div.dequeue("foo");
equal( counter, 4, "Testing previous call to dequeue" ); assert.equal( counter, 4, "Testing previous call to dequeue" );
equal( $div.queue("foo").length, 0, "Testing queue length" ); assert.equal( $div.queue("foo").length, 0, "Testing queue length" );
$div.dequeue("foo"); $div.dequeue("foo");
equal( counter, 4, "Testing previous call to dequeue" ); assert.equal( counter, 4, "Testing previous call to dequeue" );
equal( $div.queue("foo").length, 0, "Testing queue length" ); assert.equal( $div.queue("foo").length, 0, "Testing queue length" );
}); });
test("queue(name) passes in the next item in the queue as a parameter", function() { QUnit.test("queue(name) passes in the next item in the queue as a parameter", function( assert ) {
expect(2); assert.expect(2);
var div = jQuery({}), var div = jQuery({}),
counter = 0; counter = 0;
div.queue("foo", function(next) { div.queue("foo", function(next) {
equal(++counter, 1, "Dequeueing"); assert.equal(++counter, 1, "Dequeueing");
next(); next();
}).queue("foo", function(next) { }).queue("foo", function(next) {
equal(++counter, 2, "Next was called"); assert.equal(++counter, 2, "Next was called");
next(); next();
}).queue("bar", function() { }).queue("bar", function() {
equal(++counter, 3, "Other queues are not triggered by next()"); assert.equal(++counter, 3, "Other queues are not triggered by next()");
}); });
div.dequeue("foo"); div.dequeue("foo");
}); });
test("queue() passes in the next item in the queue as a parameter to fx queues", function() { QUnit.test("queue() passes in the next item in the queue as a parameter to fx queues", function( assert ) {
expect(3); assert.expect(3);
stop(); QUnit.stop();
var div = jQuery({}), var div = jQuery({}),
counter = 0; counter = 0;
div.queue(function(next) { div.queue(function(next) {
equal(++counter, 1, "Dequeueing"); assert.equal(++counter, 1, "Dequeueing");
setTimeout(function() { next(); }, 500); setTimeout(function() { next(); }, 500);
}).queue(function(next) { }).queue(function(next) {
equal(++counter, 2, "Next was called"); assert.equal(++counter, 2, "Next was called");
next(); next();
}).queue("bar", function() { }).queue("bar", function() {
equal(++counter, 3, "Other queues are not triggered by next()"); assert.equal(++counter, 3, "Other queues are not triggered by next()");
}); });
jQuery.when( div.promise("fx"), div ).done(function() { jQuery.when( div.promise("fx"), div ).done(function() {
equal(counter, 2, "Deferreds resolved"); assert.equal(counter, 2, "Deferreds resolved");
start(); QUnit.start();
}); });
}); });
test("callbacks keep their place in the queue", function() { QUnit.test("callbacks keep their place in the queue", function( assert ) {
expect(5); assert.expect(5);
stop(); QUnit.stop();
var div = jQuery("<div>"), var div = jQuery("<div>"),
counter = 0; counter = 0;
div.queue(function( next ) { div.queue(function( next ) {
equal( ++counter, 1, "Queue/callback order: first called" ); assert.equal( ++counter, 1, "Queue/callback order: first called" );
setTimeout( next, 200 ); setTimeout( next, 200 );
}).delay( 100 ).queue(function( next ) { }).delay( 100 ).queue(function( next ) {
equal( ++counter, 2, "Queue/callback order: second called" ); assert.equal( ++counter, 2, "Queue/callback order: second called" );
jQuery( this ).delay( 100 ).queue(function( next ) { jQuery( this ).delay( 100 ).queue(function( next ) {
equal( ++counter, 4, "Queue/callback order: fourth called" ); assert.equal( ++counter, 4, "Queue/callback order: fourth called" );
next(); next();
}); });
next(); next();
}).queue(function( next ) { }).queue(function( next ) {
equal( ++counter, 3, "Queue/callback order: third called" ); assert.equal( ++counter, 3, "Queue/callback order: third called" );
next(); next();
}); });
div.promise("fx").done(function() { div.promise("fx").done(function() {
equal(counter, 4, "Deferreds resolved"); assert.equal(counter, 4, "Deferreds resolved");
start(); QUnit.start();
}); });
}); });
test( "jQuery.queue should return array while manipulating the queue", function() { QUnit.test( "jQuery.queue should return array while manipulating the queue", function( assert ) {
expect( 1 ); assert.expect( 1 );
var div = document.createElement("div"); var div = document.createElement("div");
ok( jQuery.isArray( jQuery.queue( div, "fx", jQuery.noop ) ), "jQuery.queue should return an array while manipulating the queue" ); assert.ok( jQuery.isArray( jQuery.queue( div, "fx", jQuery.noop ) ), "jQuery.queue should return an array while manipulating the queue" );
}); });
test("delay()", function() { QUnit.test("delay()", function( assert ) {
expect(2); assert.expect(2);
stop(); QUnit.stop();
var foo = jQuery({}), run = 0; var foo = jQuery({}), run = 0;
foo.delay(100).queue(function(){ foo.delay(100).queue(function(){
run = 1; run = 1;
ok( true, "The function was dequeued." ); assert.ok( true, "The function was dequeued." );
start(); QUnit.start();
}); });
equal( run, 0, "The delay delayed the next function from running." ); assert.equal( run, 0, "The delay delayed the next function from running." );
}); });
test("clearQueue(name) clears the queue", function() { QUnit.test("clearQueue(name) clears the queue", function( assert ) {
expect(2); assert.expect(2);
stop(); QUnit.stop();
var div = jQuery({}), var div = jQuery({}),
counter = 0; counter = 0;
@ -163,17 +163,17 @@ test("clearQueue(name) clears the queue", function() {
}); });
div.promise("foo").done(function() { div.promise("foo").done(function() {
ok( true, "dequeue resolves the deferred" ); assert.ok( true, "dequeue resolves the deferred" );
start(); QUnit.start();
}); });
div.dequeue("foo"); div.dequeue("foo");
equal(counter, 1, "the queue was cleared"); assert.equal(counter, 1, "the queue was cleared");
}); });
test("clearQueue() clears the fx queue", function() { QUnit.test("clearQueue() clears the fx queue", function( assert ) {
expect(1); assert.expect(1);
var div = jQuery({}), var div = jQuery({}),
counter = 0; counter = 0;
@ -186,51 +186,51 @@ test("clearQueue() clears the fx queue", function() {
counter++; counter++;
}); });
equal(counter, 1, "the queue was cleared"); assert.equal(counter, 1, "the queue was cleared");
div.removeData(); div.removeData();
}); });
asyncTest( "fn.promise() - called when fx queue is empty", 3, function() { QUnit.asyncTest( "fn.promise() - called when fx queue is empty", 3, function( assert ) {
var foo = jQuery( "#foo" ).clone().addBack(), var foo = jQuery( "#foo" ).clone().addBack(),
promised = false; promised = false;
foo.queue( function( next ) { foo.queue( function( next ) {
// called twice! // called twice!
ok( !promised, "Promised hasn't been called" ); assert.ok( !promised, "Promised hasn't been called" );
setTimeout( next, 10 ); setTimeout( next, 10 );
}); });
foo.promise().done( function() { foo.promise().done( function() {
ok( promised = true, "Promised" ); assert.ok( promised = true, "Promised" );
start(); QUnit.start();
}); });
}); });
asyncTest( "fn.promise( \"queue\" ) - called whenever last queue function is dequeued", 5, function() { QUnit.asyncTest( "fn.promise( \"queue\" ) - called whenever last queue function is dequeued", 5, function( assert ) {
var foo = jQuery( "#foo" ), var foo = jQuery( "#foo" ),
test; test;
foo.promise( "queue" ).done( function() { foo.promise( "queue" ).done( function() {
strictEqual( test, undefined, "called immediately when queue was already empty" ); assert.strictEqual( test, undefined, "called immediately when queue was already empty" );
}); });
test = 1; test = 1;
foo.queue( "queue", function( next ) { foo.queue( "queue", function( next ) {
strictEqual( test++, 1, "step one" ); assert.strictEqual( test++, 1, "step one" );
setTimeout( next, 0 ); setTimeout( next, 0 );
}).queue( "queue", function( next ) { }).queue( "queue", function( next ) {
strictEqual( test++, 2, "step two" ); assert.strictEqual( test++, 2, "step two" );
setTimeout( function() { setTimeout( function() {
next(); next();
strictEqual( test++, 4, "step four" ); assert.strictEqual( test++, 4, "step four" );
start(); QUnit.start();
}, 10 ); }, 10 );
}).promise( "queue" ).done( function() { }).promise( "queue" ).done( function() {
strictEqual( test++, 3, "step three" ); assert.strictEqual( test++, 3, "step three" );
}); });
foo.dequeue( "queue" ); foo.dequeue( "queue" );
}); });
asyncTest( "fn.promise( \"queue\" ) - waits for animation to complete before resolving", 2, function() { QUnit.asyncTest( "fn.promise( \"queue\" ) - waits for animation to complete before resolving", 2, function( assert ) {
var foo = jQuery( "#foo" ), var foo = jQuery( "#foo" ),
test = 1; test = 1;
@ -240,44 +240,44 @@ asyncTest( "fn.promise( \"queue\" ) - waits for animation to complete before res
duration: 1, duration: 1,
queue: "queue", queue: "queue",
complete: function() { complete: function() {
strictEqual( test++, 1, "step one" ); assert.strictEqual( test++, 1, "step one" );
} }
}).dequeue( "queue" ); }).dequeue( "queue" );
foo.promise( "queue" ).done( function() { foo.promise( "queue" ).done( function() {
strictEqual( test++, 2, "step two" ); assert.strictEqual( test++, 2, "step two" );
start(); QUnit.start();
}); });
}); });
test( ".promise(obj)", function() { QUnit.test( ".promise(obj)", function( assert ) {
expect(2); assert.expect(2);
var obj = {}, var obj = {},
promise = jQuery( "#foo" ).promise( "promise", obj ); promise = jQuery( "#foo" ).promise( "promise", obj );
ok( jQuery.isFunction( promise.promise ), ".promise(type, obj) returns a promise" ); assert.ok( jQuery.isFunction( promise.promise ), ".promise(type, obj) returns a promise" );
strictEqual( promise, obj, ".promise(type, obj) returns obj" ); assert.strictEqual( promise, obj, ".promise(type, obj) returns obj" );
}); });
if ( jQuery.fn.stop ) { if ( jQuery.fn.stop ) {
test("delay() can be stopped", function() { QUnit.test("delay() can be stopped", function( assert ) {
expect( 3 ); assert.expect( 3 );
stop(); QUnit.stop();
var done = {}; var done = {};
jQuery({}) jQuery({})
.queue( "alternate", function( next ) { .queue( "alternate", function( next ) {
done.alt1 = true; done.alt1 = true;
ok( true, "This first function was dequeued" ); assert.ok( true, "This first function was dequeued" );
next(); next();
}) })
.delay( 1000, "alternate" ) .delay( 1000, "alternate" )
.queue( "alternate", function() { .queue( "alternate", function() {
done.alt2 = true; done.alt2 = true;
ok( true, "The function was dequeued immediately, the delay was stopped" ); assert.ok( true, "The function was dequeued immediately, the delay was stopped" );
}) })
.dequeue( "alternate" ) .dequeue( "alternate" )
@ -288,33 +288,33 @@ if ( jQuery.fn.stop ) {
.delay( 1 ) .delay( 1 )
.queue(function() { .queue(function() {
done.default1 = true; done.default1 = true;
ok( false, "This queue should never run" ); assert.ok( false, "This queue should never run" );
}) })
// stop( clearQueue ) should clear the queue // stop( clearQueue ) should clear the queue
.stop( true, false ); .stop( true, false );
deepEqual( done, { alt1: true, alt2: true }, "Queue ran the proper functions" ); assert.deepEqual( done, { alt1: true, alt2: true }, "Queue ran the proper functions" );
setTimeout(function() { setTimeout(function() {
start(); QUnit.start();
}, 1500 ); }, 1500 );
}); });
asyncTest( "queue stop hooks", 2, function() { QUnit.asyncTest( "queue stop hooks", 2, function( assert ) {
var foo = jQuery( "#foo" ); var foo = jQuery( "#foo" );
foo.queue( function( next, hooks ) { foo.queue( function( next, hooks ) {
hooks.stop = function( gotoEnd ) { hooks.stop = function( gotoEnd ) {
equal( !!gotoEnd, false, "Stopped without gotoEnd" ); assert.equal( !!gotoEnd, false, "Stopped without gotoEnd" );
}; };
}); });
foo.stop(); foo.stop();
foo.queue( function( next, hooks ) { foo.queue( function( next, hooks ) {
hooks.stop = function( gotoEnd ) { hooks.stop = function( gotoEnd ) {
equal( gotoEnd, true, "Stopped with gotoEnd" ); assert.equal( gotoEnd, true, "Stopped with gotoEnd" );
start(); QUnit.start();
}; };
}); });

View File

@ -1,4 +1,4 @@
module( "event" ); QUnit.module( "event" );
(function() { (function() {
var notYetReady, noEarlyExecution, var notYetReady, noEarlyExecution,
@ -7,11 +7,11 @@ module( "event" );
notYetReady = !jQuery.isReady; notYetReady = !jQuery.isReady;
test( "jQuery.isReady", function() { QUnit.test( "jQuery.isReady", function( assert ) {
expect( 2 ); assert.expect( 2 );
equal( notYetReady, true, "jQuery.isReady should not be true before DOM ready" ); assert.equal( notYetReady, true, "jQuery.isReady should not be true before DOM ready" );
equal( jQuery.isReady, true, "jQuery.isReady should be true once DOM is ready" ); assert.equal( jQuery.isReady, true, "jQuery.isReady should be true once DOM is ready" );
}); });
// Create an event handler. // Create an event handler.
@ -37,20 +37,20 @@ module( "event" );
noEarlyExecution = order.length === 0; noEarlyExecution = order.length === 0;
// This assumes that QUnit tests are run on DOM ready! // This assumes that QUnit tests are run on DOM ready!
test( "jQuery ready", function() { QUnit.test( "jQuery ready", function( assert ) {
expect( 8 ); assert.expect( 8 );
ok( noEarlyExecution, assert.ok( noEarlyExecution,
"Handlers bound to DOM ready should not execute before DOM ready" ); "Handlers bound to DOM ready should not execute before DOM ready" );
// Ensure execution order. // Ensure execution order.
deepEqual( order, [ "a", "b", "c", "d" ], assert.deepEqual( order, [ "a", "b", "c", "d" ],
"Bound DOM ready handlers should execute in on-order" ); "Bound DOM ready handlers should execute in on-order" );
// Ensure handler argument is correct. // Ensure handler argument is correct.
equal( args.a, jQuery, assert.equal( args.a, jQuery,
"Argument passed to fn in jQuery( fn ) should be jQuery" ); "Argument passed to fn in jQuery( fn ) should be jQuery" );
equal( args.b, jQuery, assert.equal( args.b, jQuery,
"Argument passed to fn in jQuery(document).ready( fn ) should be jQuery" ); "Argument passed to fn in jQuery(document).ready( fn ) should be jQuery" );
order = []; order = [];
@ -58,12 +58,12 @@ module( "event" );
// Now that the ready event has fired, again bind to the ready event // Now that the ready event has fired, again bind to the ready event
// in every possible way. These event handlers should execute immediately. // in every possible way. These event handlers should execute immediately.
jQuery( makeHandler( "g" ) ); jQuery( makeHandler( "g" ) );
equal( order.pop(), "g", "Event handler should execute immediately" ); assert.equal( order.pop(), "g", "Event handler should execute immediately" );
equal( args.g, jQuery, "Argument passed to fn in jQuery( fn ) should be jQuery" ); assert.equal( args.g, jQuery, "Argument passed to fn in jQuery( fn ) should be jQuery" );
jQuery( document ).ready( makeHandler( "h" ) ); jQuery( document ).ready( makeHandler( "h" ) );
equal( order.pop(), "h", "Event handler should execute immediately" ); assert.equal( order.pop(), "h", "Event handler should execute immediately" );
equal( args.h, jQuery, assert.equal( args.h, jQuery,
"Argument passed to fn in jQuery(document).ready( fn ) should be jQuery" ); "Argument passed to fn in jQuery(document).ready( fn ) should be jQuery" );
}); });

View File

@ -1,28 +1,28 @@
module("selector", { teardown: moduleTeardown }); QUnit.module("selector", { teardown: moduleTeardown });
/** /**
* This test page is for selector tests that require jQuery in order to do the selection * This test page is for selector tests that require jQuery in order to do the selection
*/ */
test("element - jQuery only", function() { QUnit.test("element - jQuery only", function( assert ) {
expect( 7 ); assert.expect( 7 );
var fixture = document.getElementById("qunit-fixture"); var fixture = document.getElementById("qunit-fixture");
deepEqual( jQuery("p", fixture).get(), q("firstp","ap","sndp","en","sap","first"), "Finding elements with a Node context." ); assert.deepEqual( jQuery("p", fixture).get(), q("firstp","ap","sndp","en","sap","first"), "Finding elements with a Node context." );
deepEqual( jQuery("p", "#qunit-fixture").get(), q("firstp","ap","sndp","en","sap","first"), "Finding elements with a selector context." ); assert.deepEqual( jQuery("p", "#qunit-fixture").get(), q("firstp","ap","sndp","en","sap","first"), "Finding elements with a selector context." );
deepEqual( jQuery("p", jQuery("#qunit-fixture")).get(), q("firstp","ap","sndp","en","sap","first"), "Finding elements with a jQuery object context." ); assert.deepEqual( jQuery("p", jQuery("#qunit-fixture")).get(), q("firstp","ap","sndp","en","sap","first"), "Finding elements with a jQuery object context." );
deepEqual( jQuery("#qunit-fixture").find("p").get(), q("firstp","ap","sndp","en","sap","first"), "Finding elements with a context via .find()." ); assert.deepEqual( jQuery("#qunit-fixture").find("p").get(), q("firstp","ap","sndp","en","sap","first"), "Finding elements with a context via .find()." );
ok( jQuery("#length").length, "<input name=\"length\"> cannot be found under IE, see #945" ); assert.ok( jQuery("#length").length, "<input name=\"length\"> cannot be found under IE, see #945" );
ok( jQuery("#lengthtest input").length, "<input name=\"length\"> cannot be found under IE, see #945" ); assert.ok( jQuery("#lengthtest input").length, "<input name=\"length\"> cannot be found under IE, see #945" );
// #7533 // #7533
equal( jQuery("<div id=\"A'B~C.D[E]\"><p>foo</p></div>").find("p").length, 1, "Find where context root is a node and has an ID with CSS3 meta characters" ); assert.equal( jQuery("<div id=\"A'B~C.D[E]\"><p>foo</p></div>").find("p").length, 1, "Find where context root is a node and has an ID with CSS3 meta characters" );
}); });
test("id", function() { QUnit.test("id", function( assert ) {
expect( 26 ); assert.expect( 26 );
var a; var a;
@ -63,17 +63,17 @@ test("id", function() {
t( "ID with weird characters in it", "#name\\+value", ["name+value"] ); t( "ID with weird characters in it", "#name\\+value", ["name+value"] );
}); });
test("class - jQuery only", function() { QUnit.test("class - jQuery only", function( assert ) {
expect( 4 ); assert.expect( 4 );
deepEqual( jQuery(".blog", document.getElementsByTagName("p")).get(), q("mark", "simon"), "Finding elements with a context." ); assert.deepEqual( jQuery(".blog", document.getElementsByTagName("p")).get(), q("mark", "simon"), "Finding elements with a context." );
deepEqual( jQuery(".blog", "p").get(), q("mark", "simon"), "Finding elements with a context." ); assert.deepEqual( jQuery(".blog", "p").get(), q("mark", "simon"), "Finding elements with a context." );
deepEqual( jQuery(".blog", jQuery("p")).get(), q("mark", "simon"), "Finding elements with a context." ); assert.deepEqual( jQuery(".blog", jQuery("p")).get(), q("mark", "simon"), "Finding elements with a context." );
deepEqual( jQuery("p").find(".blog").get(), q("mark", "simon"), "Finding elements with a context." ); assert.deepEqual( jQuery("p").find(".blog").get(), q("mark", "simon"), "Finding elements with a context." );
}); });
test("name", function() { QUnit.test("name", function( assert ) {
expect( 5 ); assert.expect( 5 );
var form; var form;
@ -84,24 +84,24 @@ test("name", function() {
t( "Name selector for grouped input", "input[name='types[]']", ["types_all", "types_anime", "types_movie"] ); t( "Name selector for grouped input", "input[name='types[]']", ["types_all", "types_anime", "types_movie"] );
form = jQuery("<form><input name='id'/></form>").appendTo("body"); form = jQuery("<form><input name='id'/></form>").appendTo("body");
equal( jQuery("input", form[0]).length, 1, "Make sure that rooted queries on forms (with possible expandos) work." ); assert.equal( jQuery("input", form[0]).length, 1, "Make sure that rooted queries on forms (with possible expandos) work." );
form.remove(); form.remove();
}); });
test( "selectors with comma", function() { QUnit.test( "selectors with comma", function( assert ) {
expect( 4 ); assert.expect( 4 );
var fixture = jQuery( "<div><h2><span/></h2><div><p><span/></p><p/></div></div>" ); var fixture = jQuery( "<div><h2><span/></h2><div><p><span/></p><p/></div></div>" );
equal( fixture.find( "h2, div p" ).filter( "p" ).length, 2, "has to find two <p>" ); assert.equal( fixture.find( "h2, div p" ).filter( "p" ).length, 2, "has to find two <p>" );
equal( fixture.find( "h2, div p" ).filter( "h2" ).length, 1, "has to find one <h2>" ); assert.equal( fixture.find( "h2, div p" ).filter( "h2" ).length, 1, "has to find one <h2>" );
equal( fixture.find( "h2 , div p" ).filter( "p" ).length, 2, "has to find two <p>" ); assert.equal( fixture.find( "h2 , div p" ).filter( "p" ).length, 2, "has to find two <p>" );
equal( fixture.find( "h2 , div p" ).filter( "h2" ).length, 1, "has to find one <h2>" ); assert.equal( fixture.find( "h2 , div p" ).filter( "h2" ).length, 1, "has to find one <h2>" );
}); });
test( "child and adjacent", function() { QUnit.test( "child and adjacent", function( assert ) {
expect( 27 ); assert.expect( 27 );
var nothiddendiv; var nothiddendiv;
@ -127,10 +127,10 @@ test( "child and adjacent", function() {
t( "Multiple sibling combinators doesn't miss general siblings", "#siblingTest > em:first-child + em ~ span", ["siblingspan"] ); t( "Multiple sibling combinators doesn't miss general siblings", "#siblingTest > em:first-child + em ~ span", ["siblingspan"] );
t( "Combinators are not skipped when mixing general and specific", "#siblingTest > em:contains('x') + em ~ span", [] ); t( "Combinators are not skipped when mixing general and specific", "#siblingTest > em:contains('x') + em ~ span", [] );
equal( jQuery("#listWithTabIndex").length, 1, "Parent div for next test is found via ID (#8310)" ); assert.equal( jQuery("#listWithTabIndex").length, 1, "Parent div for next test is found via ID (#8310)" );
equal( jQuery("#listWithTabIndex li:eq(2) ~ li").length, 1, "Find by general sibling combinator (#8310)" ); assert.equal( jQuery("#listWithTabIndex li:eq(2) ~ li").length, 1, "Find by general sibling combinator (#8310)" );
equal( jQuery("#__sizzle__").length, 0, "Make sure the temporary id assigned by sizzle is cleared out (#8310)" ); assert.equal( jQuery("#__sizzle__").length, 0, "Make sure the temporary id assigned by sizzle is cleared out (#8310)" );
equal( jQuery("#listWithTabIndex").length, 1, "Parent div for previous test is still found via ID (#8310)" ); assert.equal( jQuery("#listWithTabIndex").length, 1, "Parent div for previous test is still found via ID (#8310)" );
t( "Verify deep class selector", "div.blah > p > a", [] ); t( "Verify deep class selector", "div.blah > p > a", [] );
@ -141,8 +141,8 @@ test( "child and adjacent", function() {
t( "Non-existent ancestors", ".fototab > .thumbnails > a", [] ); t( "Non-existent ancestors", ".fototab > .thumbnails > a", [] );
}); });
test("attributes", function() { QUnit.test("attributes", function( assert ) {
expect( 54 ); assert.expect( 54 );
var attrbad, div, withScript; var attrbad, div, withScript;
@ -221,7 +221,7 @@ test("attributes", function() {
t( "input[type=search]", "#form input[type=search]", ["search"] ); t( "input[type=search]", "#form input[type=search]", ["search"] );
withScript = supportjQuery( "<div><span><script src=''/></span></div>" ); withScript = supportjQuery( "<div><span><script src=''/></span></div>" );
ok( withScript.find( "#moretests script[src]" ).has( "script" ), "script[src] (jQuery #13777)" ); assert.ok( withScript.find( "#moretests script[src]" ).has( "script" ), "script[src] (jQuery #13777)" );
div = document.getElementById("foo"); div = document.getElementById("foo");
t( "Object.prototype property \"constructor\" (negative)", "[constructor]", [] ); t( "Object.prototype property \"constructor\" (negative)", "[constructor]", [] );
@ -234,45 +234,48 @@ test("attributes", function() {
t( "Value attribute is retrieved correctly", "input[value=Test]", ["text1", "text2"] ); t( "Value attribute is retrieved correctly", "input[value=Test]", ["text1", "text2"] );
// #12600 // #12600
ok( assert.ok(
jQuery("<select value='12600'><option value='option' selected='selected'></option><option value=''></option></select>") jQuery("<select value='12600'><option value='option' selected='selected'></option><option value=''></option></select>")
.prop( "value", "option" ) .prop( "value", "option" )
.is(":input[value='12600']"), .is(":input[value='12600']"),
":input[value=foo] selects select by attribute" ":input[value=foo] selects select by attribute"
); );
ok( jQuery("<input type='text' value='12600'/>").prop( "value", "option" ).is(":input[value='12600']"), assert.ok( jQuery("<input type='text' value='12600'/>").prop( "value", "option" ).is(":input[value='12600']"),
":input[value=foo] selects text input by attribute" ":input[value=foo] selects text input by attribute"
); );
// #11115 // #11115
ok( jQuery("<input type='checkbox' checked='checked'/>").prop( "checked", false ).is("[checked]"), assert.ok( jQuery("<input type='checkbox' checked='checked'/>").prop( "checked", false ).is("[checked]"),
"[checked] selects by attribute (positive)" "[checked] selects by attribute (positive)"
); );
ok( !jQuery("<input type='checkbox'/>").prop( "checked", true ).is("[checked]"), assert.ok( !jQuery("<input type='checkbox'/>").prop( "checked", true ).is("[checked]"),
"[checked] selects by attribute (negative)" "[checked] selects by attribute (negative)"
); );
}); });
test("disconnected nodes", function() { QUnit.test("disconnected nodes", function( assert ) {
expect( 1 ); assert.expect( 1 );
var $div = jQuery("<div/>"); var $div = jQuery("<div/>");
equal( $div.is("div"), true, "Make sure .is('nodeName') works on disconnected nodes." ); assert.equal( $div.is("div"), true, "Make sure .is('nodeName') works on disconnected nodes." );
}); });
test("disconnected nodes - jQuery only", function() { QUnit.test("disconnected nodes - jQuery only", function( assert ) {
expect( 3 ); assert.expect( 3 );
var $opt = jQuery("<option></option>").attr("value", "whipit").appendTo("#qunit-fixture").detach(); var $opt = jQuery("<option></option>").attr("value", "whipit").appendTo("#qunit-fixture").detach();
equal( $opt.val(), "whipit", "option value" ); assert.equal( $opt.val(), "whipit", "option value" );
equal( $opt.is(":selected"), false, "unselected option" ); assert.equal( $opt.is(":selected"), false, "unselected option" );
$opt.prop("selected", true); $opt.prop("selected", true);
equal( $opt.is(":selected"), true, "selected option" ); assert.equal( $opt.is(":selected"), true, "selected option" );
}); });
testIframe("selector/html5_selector", "attributes - jQuery.attr", function( jQuery, window, document ) { testIframe(
expect( 38 ); "selector/html5_selector",
"attributes - jQuery.attr",
function( jQuery, window, document, assert ) {
assert.expect( 38 );
/** /**
* Returns an array of elements with the given IDs * Returns an array of elements with the given IDs
@ -304,7 +307,7 @@ testIframe("selector/html5_selector", "attributes - jQuery.attr", function( jQue
s += (s && ",") + "'" + f[i].id + "'"; s += (s && ",") + "'" + f[i].id + "'";
} }
deepEqual(f, q.apply( q, c ), a + " (" + b + ")"); assert.deepEqual(f, q.apply( q, c ), a + " (" + b + ")");
} }
// ====== All known boolean attributes, including html5 booleans ====== // ====== All known boolean attributes, including html5 booleans ======
@ -358,36 +361,37 @@ testIframe("selector/html5_selector", "attributes - jQuery.attr", function( jQue
t( "tabindex selector does not retrieve all elements in IE6/7 (#8473)", t( "tabindex selector does not retrieve all elements in IE6/7 (#8473)",
"form, [tabindex]", [ "form1", "text1" ] ); "form, [tabindex]", [ "form1", "text1" ] );
t( "Improperly named form elements do not interfere with form selections (#9570)", "form[name='formName']", ["form1"] ); t( "Improperly named form elements do not interfere with form selections (#9570)", "form[name='formName']", ["form1"] );
}); }
);
test( "jQuery.contains", function() { QUnit.test( "jQuery.contains", function( assert ) {
expect( 16 ); assert.expect( 16 );
var container = document.getElementById("nonnodes"), var container = document.getElementById("nonnodes"),
element = container.firstChild, element = container.firstChild,
text = element.nextSibling, text = element.nextSibling,
nonContained = container.nextSibling, nonContained = container.nextSibling,
detached = document.createElement("a"); detached = document.createElement("a");
ok( element && element.nodeType === 1, "preliminary: found element" ); assert.ok( element && element.nodeType === 1, "preliminary: found element" );
ok( text && text.nodeType === 3, "preliminary: found text" ); assert.ok( text && text.nodeType === 3, "preliminary: found text" );
ok( nonContained, "preliminary: found non-descendant" ); assert.ok( nonContained, "preliminary: found non-descendant" );
ok( jQuery.contains(container, element), "child" ); assert.ok( jQuery.contains(container, element), "child" );
ok( jQuery.contains(container.parentNode, element), "grandchild" ); assert.ok( jQuery.contains(container.parentNode, element), "grandchild" );
ok( jQuery.contains(container, text), "text child" ); assert.ok( jQuery.contains(container, text), "text child" );
ok( jQuery.contains(container.parentNode, text), "text grandchild" ); assert.ok( jQuery.contains(container.parentNode, text), "text grandchild" );
ok( !jQuery.contains(container, container), "self" ); assert.ok( !jQuery.contains(container, container), "self" );
ok( !jQuery.contains(element, container), "parent" ); assert.ok( !jQuery.contains(element, container), "parent" );
ok( !jQuery.contains(container, nonContained), "non-descendant" ); assert.ok( !jQuery.contains(container, nonContained), "non-descendant" );
ok( !jQuery.contains(container, document), "document" ); assert.ok( !jQuery.contains(container, document), "document" );
ok( !jQuery.contains(container, document.documentElement), "documentElement (negative)" ); assert.ok( !jQuery.contains(container, document.documentElement), "documentElement (negative)" );
ok( !jQuery.contains(container, null), "Passing null does not throw an error" ); assert.ok( !jQuery.contains(container, null), "Passing null does not throw an error" );
ok( jQuery.contains(document, document.documentElement), "documentElement (positive)" ); assert.ok( jQuery.contains(document, document.documentElement), "documentElement (positive)" );
ok( jQuery.contains(document, element), "document container (positive)" ); assert.ok( jQuery.contains(document, element), "document container (positive)" );
ok( !jQuery.contains(document, detached), "document container (negative)" ); assert.ok( !jQuery.contains(document, detached), "document container (negative)" );
}); });
test("jQuery.uniqueSort", function() { QUnit.test("jQuery.uniqueSort", function( assert ) {
expect( 15 ); assert.expect( 15 );
function Arrayish( arr ) { function Arrayish( arr ) {
var i = this.length = arr.length; var i = this.length = arr.length;
@ -460,24 +464,28 @@ test("jQuery.uniqueSort", function() {
jQuery.each( tests, function( label, test ) { jQuery.each( tests, function( label, test ) {
var length = test.length || test.input.length; var length = test.length || test.input.length;
deepEqual( jQuery.uniqueSort( test.input ).slice( 0, length ), test.expected, label + " (array)" ); assert.deepEqual( jQuery.uniqueSort( test.input ).slice( 0, length ), test.expected, label + " (array)" );
deepEqual( jQuery.uniqueSort( new Arrayish(test.input) ).slice( 0, length ), test.expected, label + " (quasi-array)" ); assert.deepEqual( jQuery.uniqueSort( new Arrayish(test.input) ).slice( 0, length ), test.expected, label + " (quasi-array)" );
}); });
strictEqual( jQuery.unique, jQuery.uniqueSort, "jQuery.unique() is an alias for jQuery.uniqueSort()" ); assert.strictEqual( jQuery.unique, jQuery.uniqueSort, "jQuery.unique() is an alias for jQuery.uniqueSort()" );
}); });
testIframe("selector/sizzle_cache", "Sizzle cache collides with multiple Sizzles on a page", function( jQuery, window, document ) { testIframe(
"selector/sizzle_cache",
"Sizzle cache collides with multiple Sizzles on a page",
function( jQuery, window, document, assert ) {
var $cached = window["$cached"]; var $cached = window["$cached"];
expect(4); assert.expect(4);
notStrictEqual( jQuery, $cached, "Loaded two engines" ); assert.notStrictEqual( jQuery, $cached, "Loaded two engines" );
deepEqual( $cached(".test a").get(), [ document.getElementById("collision") ], "Select collision anchor with first sizzle" ); assert.deepEqual( $cached(".test a").get(), [ document.getElementById("collision") ], "Select collision anchor with first sizzle" );
equal( jQuery(".evil a").length, 0, "Select nothing with second sizzle" ); assert.equal( jQuery(".evil a").length, 0, "Select nothing with second sizzle" );
equal( jQuery(".evil a").length, 0, "Select nothing again with second sizzle" ); assert.equal( jQuery(".evil a").length, 0, "Select nothing again with second sizzle" );
}); }
);
asyncTest( "Iframe dispatch should not affect jQuery (#13936)", 1, function() { QUnit.asyncTest( "Iframe dispatch should not affect jQuery (#13936)", 1, function( assert ) {
var loaded = false, var loaded = false,
thrown = false, thrown = false,
iframe = document.getElementById( "iframe" ), iframe = document.getElementById( "iframe" ),
@ -494,12 +502,12 @@ asyncTest( "Iframe dispatch should not affect jQuery (#13936)", 1, function() {
} }
if ( loaded ) { if ( loaded ) {
strictEqual( thrown, false, "No error thrown from post-reload jQuery call" ); assert.strictEqual( thrown, false, "No error thrown from post-reload jQuery call" );
// clean up // clean up
jQuery( iframe ).off(); jQuery( iframe ).off();
start(); QUnit.start();
} else { } else {
loaded = true; loaded = true;
form.submit(); form.submit();

View File

@ -1,43 +1,43 @@
module("serialize", { teardown: moduleTeardown }); QUnit.module("serialize", { teardown: moduleTeardown });
test("jQuery.param()", function() { QUnit.test("jQuery.param()", function( assert ) {
expect(22); assert.expect(22);
var params, settings; var params, settings;
equal( !( jQuery.ajaxSettings && jQuery.ajaxSettings.traditional ), true, "traditional flag, falsy by default" ); assert.equal( !( jQuery.ajaxSettings && jQuery.ajaxSettings.traditional ), true, "traditional flag, falsy by default" );
params = {"foo":"bar", "baz":42, "quux":"All your base are belong to us"}; params = {"foo":"bar", "baz":42, "quux":"All your base are belong to us"};
equal( jQuery.param(params), "foo=bar&baz=42&quux=All+your+base+are+belong+to+us", "simple" ); assert.equal( jQuery.param(params), "foo=bar&baz=42&quux=All+your+base+are+belong+to+us", "simple" );
params = {"string":"foo","null":null,"undefined":undefined}; params = {"string":"foo","null":null,"undefined":undefined};
equal( jQuery.param(params), "string=foo&null=&undefined=", "handle nulls and undefineds properly" ); assert.equal( jQuery.param(params), "string=foo&null=&undefined=", "handle nulls and undefineds properly" );
params = {"someName": [1, 2, 3], "regularThing": "blah" }; params = {"someName": [1, 2, 3], "regularThing": "blah" };
equal( jQuery.param(params), "someName%5B%5D=1&someName%5B%5D=2&someName%5B%5D=3&regularThing=blah", "with array" ); assert.equal( jQuery.param(params), "someName%5B%5D=1&someName%5B%5D=2&someName%5B%5D=3&regularThing=blah", "with array" );
params = {"foo": ["a", "b", "c"]}; params = {"foo": ["a", "b", "c"]};
equal( jQuery.param(params), "foo%5B%5D=a&foo%5B%5D=b&foo%5B%5D=c", "with array of strings" ); assert.equal( jQuery.param(params), "foo%5B%5D=a&foo%5B%5D=b&foo%5B%5D=c", "with array of strings" );
params = {"foo": ["baz", 42, "All your base are belong to us"] }; params = {"foo": ["baz", 42, "All your base are belong to us"] };
equal( jQuery.param(params), "foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All+your+base+are+belong+to+us", "more array" ); assert.equal( jQuery.param(params), "foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All+your+base+are+belong+to+us", "more array" );
params = {"foo": { "bar": "baz", "beep": 42, "quux": "All your base are belong to us" } }; params = {"foo": { "bar": "baz", "beep": 42, "quux": "All your base are belong to us" } };
equal( jQuery.param(params), "foo%5Bbar%5D=baz&foo%5Bbeep%5D=42&foo%5Bquux%5D=All+your+base+are+belong+to+us", "even more arrays" ); assert.equal( jQuery.param(params), "foo%5Bbar%5D=baz&foo%5Bbeep%5D=42&foo%5Bquux%5D=All+your+base+are+belong+to+us", "even more arrays" );
params = { a:[1,2], b:{ c:3, d:[4,5], e:{ x:[6], y:7, z:[8,9] }, f:true, g:false, h:undefined }, i:[10,11], j:true, k:false, l:[undefined,0], m:"cowboy hat?" }; params = { a:[1,2], b:{ c:3, d:[4,5], e:{ x:[6], y:7, z:[8,9] }, f:true, g:false, h:undefined }, i:[10,11], j:true, k:false, l:[undefined,0], m:"cowboy hat?" };
equal( decodeURIComponent( jQuery.param(params) ), "a[]=1&a[]=2&b[c]=3&b[d][]=4&b[d][]=5&b[e][x][]=6&b[e][y]=7&b[e][z][]=8&b[e][z][]=9&b[f]=true&b[g]=false&b[h]=&i[]=10&i[]=11&j=true&k=false&l[]=&l[]=0&m=cowboy+hat?", "huge structure" ); assert.equal( decodeURIComponent( jQuery.param(params) ), "a[]=1&a[]=2&b[c]=3&b[d][]=4&b[d][]=5&b[e][x][]=6&b[e][y]=7&b[e][z][]=8&b[e][z][]=9&b[f]=true&b[g]=false&b[h]=&i[]=10&i[]=11&j=true&k=false&l[]=&l[]=0&m=cowboy+hat?", "huge structure" );
params = { "a": [ 0, [ 1, 2 ], [ 3, [ 4, 5 ], [ 6 ] ], { "b": [ 7, [ 8, 9 ], [ { "c": 10, "d": 11 } ], [ [ 12 ] ], [ [ [ 13 ] ] ], { "e": { "f": { "g": [ 14, [ 15 ] ] } } }, 16 ] }, 17 ] }; params = { "a": [ 0, [ 1, 2 ], [ 3, [ 4, 5 ], [ 6 ] ], { "b": [ 7, [ 8, 9 ], [ { "c": 10, "d": 11 } ], [ [ 12 ] ], [ [ [ 13 ] ] ], { "e": { "f": { "g": [ 14, [ 15 ] ] } } }, 16 ] }, 17 ] };
equal( decodeURIComponent( jQuery.param(params) ), "a[]=0&a[1][]=1&a[1][]=2&a[2][]=3&a[2][1][]=4&a[2][1][]=5&a[2][2][]=6&a[3][b][]=7&a[3][b][1][]=8&a[3][b][1][]=9&a[3][b][2][0][c]=10&a[3][b][2][0][d]=11&a[3][b][3][0][]=12&a[3][b][4][0][0][]=13&a[3][b][5][e][f][g][]=14&a[3][b][5][e][f][g][1][]=15&a[3][b][]=16&a[]=17", "nested arrays" ); assert.equal( decodeURIComponent( jQuery.param(params) ), "a[]=0&a[1][]=1&a[1][]=2&a[2][]=3&a[2][1][]=4&a[2][1][]=5&a[2][2][]=6&a[3][b][]=7&a[3][b][1][]=8&a[3][b][1][]=9&a[3][b][2][0][c]=10&a[3][b][2][0][d]=11&a[3][b][3][0][]=12&a[3][b][4][0][0][]=13&a[3][b][5][e][f][g][]=14&a[3][b][5][e][f][g][1][]=15&a[3][b][]=16&a[]=17", "nested arrays" );
params = { "a":[1,2], "b":{ "c":3, "d":[4,5], "e":{ "x":[6], "y":7, "z":[8,9] }, "f":true, "g":false, "h":undefined }, "i":[10,11], "j":true, "k":false, "l":[undefined,0], "m":"cowboy hat?" }; params = { "a":[1,2], "b":{ "c":3, "d":[4,5], "e":{ "x":[6], "y":7, "z":[8,9] }, "f":true, "g":false, "h":undefined }, "i":[10,11], "j":true, "k":false, "l":[undefined,0], "m":"cowboy hat?" };
equal( jQuery.param(params,true), "a=1&a=2&b=%5Bobject+Object%5D&i=10&i=11&j=true&k=false&l=&l=0&m=cowboy+hat%3F", "huge structure, forced traditional" ); assert.equal( jQuery.param(params,true), "a=1&a=2&b=%5Bobject+Object%5D&i=10&i=11&j=true&k=false&l=&l=0&m=cowboy+hat%3F", "huge structure, forced traditional" );
equal( decodeURIComponent( jQuery.param({ "a": [1,2,3], "b[]": [4,5,6], "c[d]": [7,8,9], "e": { "f": [10], "g": [11,12], "h": 13 } }) ), "a[]=1&a[]=2&a[]=3&b[]=4&b[]=5&b[]=6&c[d][]=7&c[d][]=8&c[d][]=9&e[f][]=10&e[g][]=11&e[g][]=12&e[h]=13", "Make sure params are not double-encoded." ); assert.equal( decodeURIComponent( jQuery.param({ "a": [1,2,3], "b[]": [4,5,6], "c[d]": [7,8,9], "e": { "f": [10], "g": [11,12], "h": 13 } }) ), "a[]=1&a[]=2&a[]=3&b[]=4&b[]=5&b[]=6&c[d][]=7&c[d][]=8&c[d][]=9&e[f][]=10&e[g][]=11&e[g][]=12&e[h]=13", "Make sure params are not double-encoded." );
// #7945 // #7945
equal( jQuery.param({"jquery": "1.4.2"}), "jquery=1.4.2", "Check that object with a jQuery property get serialized correctly" ); assert.equal( jQuery.param({"jquery": "1.4.2"}), "jquery=1.4.2", "Check that object with a jQuery property get serialized correctly" );
settings = { traditional: true }; settings = { traditional: true };
@ -48,34 +48,34 @@ test("jQuery.param()", function() {
} }
params = {"foo":"bar", "baz":42, "quux":"All your base are belong to us"}; params = {"foo":"bar", "baz":42, "quux":"All your base are belong to us"};
equal( jQuery.param(params), "foo=bar&baz=42&quux=All+your+base+are+belong+to+us", "simple" ); assert.equal( jQuery.param(params), "foo=bar&baz=42&quux=All+your+base+are+belong+to+us", "simple" );
params = {"someName": [1, 2, 3], "regularThing": "blah" }; params = {"someName": [1, 2, 3], "regularThing": "blah" };
equal( jQuery.param(params), "someName=1&someName=2&someName=3&regularThing=blah", "with array" ); assert.equal( jQuery.param(params), "someName=1&someName=2&someName=3&regularThing=blah", "with array" );
params = {"foo": ["a", "b", "c"]}; params = {"foo": ["a", "b", "c"]};
equal( jQuery.param(params), "foo=a&foo=b&foo=c", "with array of strings" ); assert.equal( jQuery.param(params), "foo=a&foo=b&foo=c", "with array of strings" );
params = {"foo[]":["baz", 42, "All your base are belong to us"]}; params = {"foo[]":["baz", 42, "All your base are belong to us"]};
equal( jQuery.param(params), "foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All+your+base+are+belong+to+us", "more array" ); assert.equal( jQuery.param(params), "foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All+your+base+are+belong+to+us", "more array" );
params = {"foo[bar]":"baz", "foo[beep]":42, "foo[quux]":"All your base are belong to us"}; params = {"foo[bar]":"baz", "foo[beep]":42, "foo[quux]":"All your base are belong to us"};
equal( jQuery.param(params), "foo%5Bbar%5D=baz&foo%5Bbeep%5D=42&foo%5Bquux%5D=All+your+base+are+belong+to+us", "even more arrays" ); assert.equal( jQuery.param(params), "foo%5Bbar%5D=baz&foo%5Bbeep%5D=42&foo%5Bquux%5D=All+your+base+are+belong+to+us", "even more arrays" );
params = { a:[1,2], b:{ c:3, d:[4,5], e:{ x:[6], y:7, z:[8,9] }, f:true, g:false, h:undefined }, i:[10,11], j:true, k:false, l:[undefined,0], m:"cowboy hat?" }; params = { a:[1,2], b:{ c:3, d:[4,5], e:{ x:[6], y:7, z:[8,9] }, f:true, g:false, h:undefined }, i:[10,11], j:true, k:false, l:[undefined,0], m:"cowboy hat?" };
equal( jQuery.param(params), "a=1&a=2&b=%5Bobject+Object%5D&i=10&i=11&j=true&k=false&l=&l=0&m=cowboy+hat%3F", "huge structure" ); assert.equal( jQuery.param(params), "a=1&a=2&b=%5Bobject+Object%5D&i=10&i=11&j=true&k=false&l=&l=0&m=cowboy+hat%3F", "huge structure" );
params = { "a": [ 0, [ 1, 2 ], [ 3, [ 4, 5 ], [ 6 ] ], { "b": [ 7, [ 8, 9 ], [ { "c": 10, d: 11 } ], [ [ 12 ] ], [ [ [ 13 ] ] ], { "e": { "f": { "g": [ 14, [ 15 ] ] } } }, 16 ] }, 17 ] }; params = { "a": [ 0, [ 1, 2 ], [ 3, [ 4, 5 ], [ 6 ] ], { "b": [ 7, [ 8, 9 ], [ { "c": 10, d: 11 } ], [ [ 12 ] ], [ [ [ 13 ] ] ], { "e": { "f": { "g": [ 14, [ 15 ] ] } } }, 16 ] }, 17 ] };
equal( jQuery.param(params), "a=0&a=1%2C2&a=3%2C4%2C5%2C6&a=%5Bobject+Object%5D&a=17", "nested arrays (not possible when jQuery.param.traditional == true)" ); assert.equal( jQuery.param(params), "a=0&a=1%2C2&a=3%2C4%2C5%2C6&a=%5Bobject+Object%5D&a=17", "nested arrays (not possible when jQuery.param.traditional == true)" );
params = { a:[1,2], b:{ c:3, d:[4,5], e:{ x:[6], y:7, z:[8,9] }, f:true, g:false, h:undefined }, i:[10,11], j:true, k:false, l:[undefined,0], m:"cowboy hat?" }; params = { a:[1,2], b:{ c:3, d:[4,5], e:{ x:[6], y:7, z:[8,9] }, f:true, g:false, h:undefined }, i:[10,11], j:true, k:false, l:[undefined,0], m:"cowboy hat?" };
equal( decodeURIComponent( jQuery.param(params,false) ), "a[]=1&a[]=2&b[c]=3&b[d][]=4&b[d][]=5&b[e][x][]=6&b[e][y]=7&b[e][z][]=8&b[e][z][]=9&b[f]=true&b[g]=false&b[h]=&i[]=10&i[]=11&j=true&k=false&l[]=&l[]=0&m=cowboy+hat?", "huge structure, forced not traditional" ); assert.equal( decodeURIComponent( jQuery.param(params,false) ), "a[]=1&a[]=2&b[c]=3&b[d][]=4&b[d][]=5&b[e][x][]=6&b[e][y]=7&b[e][z][]=8&b[e][z][]=9&b[f]=true&b[g]=false&b[h]=&i[]=10&i[]=11&j=true&k=false&l[]=&l[]=0&m=cowboy+hat?", "huge structure, forced not traditional" );
params = { "param1": null }; params = { "param1": null };
equal( jQuery.param(params,false), "param1=", "Make sure that null params aren't traversed." ); assert.equal( jQuery.param(params,false), "param1=", "Make sure that null params aren't traversed." );
params = {"test": {"length": 3, "foo": "bar"} }; params = {"test": {"length": 3, "foo": "bar"} };
equal( jQuery.param( params, false ), "test%5Blength%5D=3&test%5Bfoo%5D=bar", "Sub-object with a length property" ); assert.equal( jQuery.param( params, false ), "test%5Blength%5D=3&test%5Bfoo%5D=bar", "Sub-object with a length property" );
if ( jQuery.ajaxSettings === settings ) { if ( jQuery.ajaxSettings === settings ) {
delete jQuery.ajaxSettings; delete jQuery.ajaxSettings;
@ -84,8 +84,8 @@ test("jQuery.param()", function() {
} }
}); });
test("jQuery.param() Constructed prop values", function() { QUnit.test("jQuery.param() Constructed prop values", function( assert ) {
expect( 4 ); assert.expect( 4 );
/** @constructor */ /** @constructor */
function Record() { function Record() {
@ -96,21 +96,21 @@ test("jQuery.param() Constructed prop values", function() {
MyNumber = Number, MyNumber = Number,
params = { "test": new MyString("foo") }; params = { "test": new MyString("foo") };
equal( jQuery.param( params, false ), "test=foo", "Do not mistake new String() for a plain object" ); assert.equal( jQuery.param( params, false ), "test=foo", "Do not mistake new String() for a plain object" );
params = { "test": new MyNumber(5) }; params = { "test": new MyNumber(5) };
equal( jQuery.param( params, false ), "test=5", "Do not mistake new Number() for a plain object" ); assert.equal( jQuery.param( params, false ), "test=5", "Do not mistake new Number() for a plain object" );
params = { "test": new Date() }; params = { "test": new Date() };
ok( jQuery.param( params, false ), "(Non empty string returned) Do not mistake new Date() for a plain object" ); assert.ok( jQuery.param( params, false ), "(Non empty string returned) Do not mistake new Date() for a plain object" );
// should allow non-native constructed objects // should allow non-native constructed objects
params = { "test": new Record() }; params = { "test": new Record() };
equal( jQuery.param( params, false ), jQuery.param({ "test": { "prop": "val" } }), "Allow non-native constructed objects" ); assert.equal( jQuery.param( params, false ), jQuery.param({ "test": { "prop": "val" } }), "Allow non-native constructed objects" );
}); });
test("serialize()", function() { QUnit.test("serialize()", function( assert ) {
expect(6); assert.expect(6);
// Add html5 elements only for serialize because selector can't yet find them on non-html5 browsers // Add html5 elements only for serialize because selector can't yet find them on non-html5 browsers
jQuery("#search").after( jQuery("#search").after(
@ -119,27 +119,27 @@ test("serialize()", function() {
"<input type='file' name='fileupload' />" "<input type='file' name='fileupload' />"
); );
equal( jQuery("#form").serialize(), assert.equal( jQuery("#form").serialize(),
"action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3", "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3",
"Check form serialization as query string"); "Check form serialization as query string");
equal( jQuery("input,select,textarea,button", "#form").serialize(), assert.equal( jQuery("input,select,textarea,button", "#form").serialize(),
"action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3", "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3",
"Check input serialization as query string"); "Check input serialization as query string");
equal( jQuery("#testForm").serialize(), assert.equal( jQuery("#testForm").serialize(),
"T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=", "T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
"Check form serialization as query string"); "Check form serialization as query string");
equal( jQuery("input,select,textarea,button", "#testForm").serialize(), assert.equal( jQuery("input,select,textarea,button", "#testForm").serialize(),
"T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=", "T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
"Check input serialization as query string"); "Check input serialization as query string");
equal( jQuery("#form, #testForm").serialize(), assert.equal( jQuery("#form, #testForm").serialize(),
"action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3&T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=", "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3&T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
"Multiple form serialization as query string"); "Multiple form serialization as query string");
equal( jQuery("#form, #testForm :input").serialize(), assert.equal( jQuery("#form, #testForm :input").serialize(),
"action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3&T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=", "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3&T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
"Mixed form/input serialization as query string"); "Mixed form/input serialization as query string");
jQuery("#html5email, #html5number").remove(); jQuery("#html5email, #html5number").remove();

View File

@ -1,4 +1,4 @@
module("support", { teardown: moduleTeardown }); QUnit.module("support", { teardown: moduleTeardown });
var computedSupport = getComputedSupport( jQuery.support ); var computedSupport = getComputedSupport( jQuery.support );
@ -18,30 +18,35 @@ function getComputedSupport( support ) {
} }
if ( jQuery.css ) { if ( jQuery.css ) {
testIframeWithCallback( "body background is not lost if set prior to loading jQuery (#9239)", "support/bodyBackground.html", function( color, support ) { testIframeWithCallback(
expect( 2 ); "body background is not lost if set prior to loading jQuery (#9239)",
"support/bodyBackground.html",
function( color, support, assert ) {
assert.expect( 2 );
var okValue = { var okValue = {
"#000000": true, "#000000": true,
"rgb(0, 0, 0)": true "rgb(0, 0, 0)": true
}; };
ok( okValue[ color ], "color was not reset (" + color + ")" ); assert.ok( okValue[ color ], "color was not reset (" + color + ")" );
deepEqual( jQuery.extend( {}, support ), computedSupport, "Same support properties" ); assert.deepEqual( jQuery.extend( {}, support ), computedSupport, "Same support properties" );
}); }
);
} }
// This test checks CSP only for browsers with "Content-Security-Policy" header support // This test checks CSP only for browsers with "Content-Security-Policy" header support
// i.e. no old WebKit or old Firefox // i.e. no old WebKit or old Firefox
testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Security/CSP) restrictions", testIframeWithCallback(
"Check CSP (https://developer.mozilla.org/en-US/docs/Security/CSP) restrictions",
"support/csp.php", "support/csp.php",
function( support ) { function( support, assert ) {
expect( 2 ); assert.expect( 2 );
deepEqual( jQuery.extend( {}, support ), computedSupport, "No violations of CSP polices" ); assert.deepEqual( jQuery.extend( {}, support ), computedSupport, "No violations of CSP polices" );
stop(); QUnit.stop();
supportjQuery.get( "data/support/csp.log" ).done(function( data ) { supportjQuery.get( "data/support/csp.log" ).done(function( data ) {
equal( data, "", "No log request should be sent" ); assert.equal( data, "", "No log request should be sent" );
supportjQuery.get( "data/support/csp-clean.php" ).done( start ); supportjQuery.get( "data/support/csp-clean.php" ).done( start );
}); });
} }
@ -254,7 +259,7 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
} }
if ( expected ) { if ( expected ) {
test( "Verify that the support tests resolve as expected per browser", function() { QUnit.test( "Verify that the support tests resolve as expected per browser", function( assert ) {
var i, prop, var i, prop,
j = 0; j = 0;
@ -262,16 +267,16 @@ testIframeWithCallback( "Check CSP (https://developer.mozilla.org/en-US/docs/Sec
j++; j++;
} }
expect( j ); assert.expect( j );
for ( i in expected ) { for ( i in expected ) {
// TODO check for all modules containing support properties // TODO check for all modules containing support properties
if ( jQuery.ajax || i !== "ajax" && i !== "cors" ) { if ( jQuery.ajax || i !== "ajax" && i !== "cors" ) {
equal( computedSupport[ i ], expected[ i ], assert.equal( computedSupport[ i ], expected[ i ],
"jQuery.support['" + i + "']: " + computedSupport[ i ] + "jQuery.support['" + i + "']: " + computedSupport[ i ] +
", expected['" + i + "']: " + expected[ i ]); ", expected['" + i + "']: " + expected[ i ]);
} else { } else {
ok( true, "no ajax; skipping jQuery.support[' " + i + " ']" ); assert.ok( true, "no ajax; skipping jQuery.support[' " + i + " ']" );
} }
} }
}); });

File diff suppressed because it is too large Load Diff

View File

@ -7,7 +7,7 @@ if ( !jQuery.fx ) {
var oldRaf = window.requestAnimationFrame; var oldRaf = window.requestAnimationFrame;
module( "tween", { QUnit.module( "tween", {
setup: function() { setup: function() {
window.requestAnimationFrame = null; window.requestAnimationFrame = null;
this.sandbox = sinon.sandbox.create(); this.sandbox = sinon.sandbox.create();
@ -27,79 +27,79 @@ module( "tween", {
} }
} ); } );
test( "jQuery.Tween - Default propHooks on plain objects", function() { QUnit.test( "jQuery.Tween - Default propHooks on plain objects", function( assert ) {
expect( 8 ); assert.expect( 8 );
var propHooks, defaultHook, testObject, fakeTween, stepSpy; var propHooks, defaultHook, testObject, fakeTween, stepSpy;
propHooks = jQuery.Tween.propHooks; propHooks = jQuery.Tween.propHooks;
equal( typeof propHooks, "object", "jQuery.Tween.propHooks exists" ); assert.equal( typeof propHooks, "object", "jQuery.Tween.propHooks exists" );
defaultHook = propHooks._default; defaultHook = propHooks._default;
ok( defaultHook, "_default propHook exists" ); assert.ok( defaultHook, "_default propHook exists" );
testObject = { test: 0 }; testObject = { test: 0 };
fakeTween = { elem: testObject, prop: "test", now: 10, unit: "px" }; fakeTween = { elem: testObject, prop: "test", now: 10, unit: "px" };
equal( defaultHook.get( fakeTween ), 0, "Can get property of object" ); assert.equal( defaultHook.get( fakeTween ), 0, "Can get property of object" );
fakeTween.prop = "testMissing"; fakeTween.prop = "testMissing";
equal( defaultHook.get( fakeTween ), undefined, "Can get missing property on object" ); assert.equal( defaultHook.get( fakeTween ), undefined, "Can get missing property on object" );
defaultHook.set( fakeTween ); defaultHook.set( fakeTween );
equal( testObject.testMissing, 10, "Sets missing value properly on plain object" ); assert.equal( testObject.testMissing, 10, "Sets missing value properly on plain object" );
fakeTween.prop = "opacity"; fakeTween.prop = "opacity";
defaultHook.set( fakeTween ); defaultHook.set( fakeTween );
equal( testObject.opacity, 10, "Correctly set opacity on plain object" ); assert.equal( testObject.opacity, 10, "Correctly set opacity on plain object" );
fakeTween.prop = "test"; fakeTween.prop = "test";
stepSpy = jQuery.fx.step.test = this.sandbox.spy(); stepSpy = jQuery.fx.step.test = this.sandbox.spy();
defaultHook.set( fakeTween ); defaultHook.set( fakeTween );
ok( stepSpy.calledWith( fakeTween ), "Step function called with Tween" ); assert.ok( stepSpy.calledWith( fakeTween ), "Step function called with Tween" );
equal( testObject.test, 0, "Because step didn't set, value is unchanged" ); assert.equal( testObject.test, 0, "Because step didn't set, value is unchanged" );
} ); } );
test( "jQuery.Tween - Default propHooks on elements", function() { QUnit.test( "jQuery.Tween - Default propHooks on elements", function( assert ) {
expect( 19 ); assert.expect( 19 );
var propHooks, defaultHook, testElement, fakeTween, cssStub, styleStub, stepSpy; var propHooks, defaultHook, testElement, fakeTween, cssStub, styleStub, stepSpy;
propHooks = jQuery.Tween.propHooks; propHooks = jQuery.Tween.propHooks;
equal( typeof propHooks, "object", "jQuery.Tween.propHooks exists" ); assert.equal( typeof propHooks, "object", "jQuery.Tween.propHooks exists" );
defaultHook = propHooks._default; defaultHook = propHooks._default;
ok( defaultHook, "_default propHook exists" ); assert.ok( defaultHook, "_default propHook exists" );
testElement = jQuery( "<div>" )[ 0 ]; testElement = jQuery( "<div>" )[ 0 ];
fakeTween = { elem: testElement, prop: "height", now: 10, unit: "px" }; fakeTween = { elem: testElement, prop: "height", now: 10, unit: "px" };
cssStub = this.sandbox.stub( jQuery, "css" ).returns( 10 ); cssStub = this.sandbox.stub( jQuery, "css" ).returns( 10 );
equal( defaultHook.get( fakeTween ), 10, "Gets expected style value" ); assert.equal( defaultHook.get( fakeTween ), 10, "Gets expected style value" );
ok( cssStub.calledWith( testElement, "height", "" ), "Calls jQuery.css correctly" ); assert.ok( cssStub.calledWith( testElement, "height", "" ), "Calls jQuery.css correctly" );
fakeTween.prop = "testOpti"; fakeTween.prop = "testOpti";
testElement.testOpti = 15; testElement.testOpti = 15;
cssStub.reset(); cssStub.reset();
equal( defaultHook.get( fakeTween ), 15, "Gets expected value not defined on style" ); assert.equal( defaultHook.get( fakeTween ), 15, "Gets expected value not defined on style" );
equal( cssStub.callCount, 0, "Did not call jQuery.css" ); assert.equal( cssStub.callCount, 0, "Did not call jQuery.css" );
fakeTween.prop = "testMissing"; fakeTween.prop = "testMissing";
equal( defaultHook.get( fakeTween ), 10, "Can get missing property on element" ); assert.equal( defaultHook.get( fakeTween ), 10, "Can get missing property on element" );
ok( cssStub.calledWith( testElement, "testMissing", "" ), "...using jQuery.css" ); assert.ok( cssStub.calledWith( testElement, "testMissing", "" ), "...using jQuery.css" );
cssStub.returns( "" ); cssStub.returns( "" );
equal( defaultHook.get( fakeTween ), 0, "Uses 0 for empty string" ); assert.equal( defaultHook.get( fakeTween ), 0, "Uses 0 for empty string" );
cssStub.returns( "auto" ); cssStub.returns( "auto" );
equal( defaultHook.get( fakeTween ), 0, "Uses 0 for 'auto'" ); assert.equal( defaultHook.get( fakeTween ), 0, "Uses 0 for 'auto'" );
cssStub.returns( null ); cssStub.returns( null );
equal( defaultHook.get( fakeTween ), 0, "Uses 0 for null" ); assert.equal( defaultHook.get( fakeTween ), 0, "Uses 0 for null" );
cssStub.returns( undefined ); cssStub.returns( undefined );
equal( defaultHook.get( fakeTween ), 0, "Uses 0 for undefined" ); assert.equal( defaultHook.get( fakeTween ), 0, "Uses 0 for undefined" );
cssStub.reset(); cssStub.reset();
@ -108,15 +108,15 @@ test( "jQuery.Tween - Default propHooks on elements", function() {
fakeTween.prop = "height"; fakeTween.prop = "height";
defaultHook.set( fakeTween ); defaultHook.set( fakeTween );
ok( styleStub.calledWith( testElement, "height", "10px" ), assert.ok( styleStub.calledWith( testElement, "height", "10px" ),
"Calls jQuery.style with elem, prop, now+unit" ); "Calls jQuery.style with elem, prop, now+unit" );
styleStub.reset(); styleStub.reset();
fakeTween.prop = "testMissing"; fakeTween.prop = "testMissing";
defaultHook.set( fakeTween ); defaultHook.set( fakeTween );
equal( styleStub.callCount, 0, "Did not call jQuery.style for non css property" ); assert.equal( styleStub.callCount, 0, "Did not call jQuery.style for non css property" );
equal( testElement.testMissing, 10, "Instead, set value on element directly" ); assert.equal( testElement.testMissing, 10, "Instead, set value on element directly" );
jQuery.cssHooks.testMissing = jQuery.noop; jQuery.cssHooks.testMissing = jQuery.noop;
fakeTween.now = 11; fakeTween.now = 11;
@ -124,91 +124,100 @@ test( "jQuery.Tween - Default propHooks on elements", function() {
defaultHook.set( fakeTween ); defaultHook.set( fakeTween );
delete jQuery.cssHooks.testMissing; delete jQuery.cssHooks.testMissing;
ok( styleStub.calledWith( testElement, "testMissing", "11px" ), assert.ok( styleStub.calledWith( testElement, "testMissing", "11px" ),
"Presence of cssHooks causes jQuery.style with elem, prop, now+unit" ); "Presence of cssHooks causes jQuery.style with elem, prop, now+unit" );
equal( testElement.testMissing, 10, "And value was unchanged" ); assert.equal( testElement.testMissing, 10, "And value was unchanged" );
stepSpy = jQuery.fx.step.test = this.sandbox.spy(); stepSpy = jQuery.fx.step.test = this.sandbox.spy();
styleStub.reset(); styleStub.reset();
fakeTween.prop = "test"; fakeTween.prop = "test";
defaultHook.set( fakeTween ); defaultHook.set( fakeTween );
ok( stepSpy.calledWith( fakeTween ), "Step function called with Tween" ); assert.ok( stepSpy.calledWith( fakeTween ), "Step function called with Tween" );
equal( styleStub.callCount, 0, "Did not call jQuery.style" ); assert.equal( styleStub.callCount, 0, "Did not call jQuery.style" );
} ); } );
test( "jQuery.Tween - Plain Object", function() { QUnit.test( "jQuery.Tween - Plain Object", function( assert ) {
expect( 13 ); assert.expect( 13 );
var testObject = { test: 100 }, var testObject = { test: 100 },
testOptions = { duration: 100 }, testOptions = { duration: 100 },
tween, easingSpy; tween, easingSpy;
tween = jQuery.Tween( testObject, testOptions, "test", 0, "linear" ); tween = jQuery.Tween( testObject, testOptions, "test", 0, "linear" );
equal( tween.elem, testObject, "Sets .element" ); assert.equal( tween.elem, testObject, "Sets .element" );
equal( tween.options, testOptions, "sets .options" ); assert.equal( tween.options, testOptions, "sets .options" );
equal( tween.prop, "test", "sets .prop" ); assert.equal( tween.prop, "test", "sets .prop" );
equal( tween.end, 0, "sets .end" ); assert.equal( tween.end, 0, "sets .end" );
equal( tween.easing, "linear", "sets .easing when provided" ); assert.equal( tween.easing, "linear", "sets .easing when provided" );
equal( tween.start, 100, "Reads .start value during construction" ); assert.equal( tween.start, 100, "Reads .start value during construction" );
equal( tween.now, 100, "Reads .now value during construction" ); assert.equal( tween.now, 100, "Reads .now value during construction" );
easingSpy = this.sandbox.spy( jQuery.easing, "linear" ); easingSpy = this.sandbox.spy( jQuery.easing, "linear" );
equal( tween.run( 0.1 ), tween, ".run() returns this" ); assert.equal( tween.run( 0.1 ), tween, ".run() returns this" );
equal( tween.now, 90, "Calculated tween" ); assert.equal( tween.now, 90, "Calculated tween" );
ok( easingSpy.calledWith( 0.1, 0.1 * testOptions.duration, 0, 1, testOptions.duration ), assert.ok( easingSpy.calledWith( 0.1, 0.1 * testOptions.duration, 0, 1, testOptions.duration ),
"...using jQuery.easing.linear with back-compat arguments" ); "...using jQuery.easing.linear with back-compat arguments" );
equal( testObject.test, 90, "Set value" ); assert.equal( testObject.test, 90, "Set value" );
tween.run( 1 ); tween.run( 1 );
equal( testObject.test, 0, "Checking another value" ); assert.equal( testObject.test, 0, "Checking another value" );
tween.run( 0 ); tween.run( 0 );
equal( testObject.test, 100, "Can even go back in time" ); assert.equal( testObject.test, 100, "Can even go back in time" );
} ); } );
test( "jQuery.Tween - Element", function() { QUnit.test( "jQuery.Tween - Element", function( assert ) {
expect( 15 ); assert.expect( 15 );
var testElement = jQuery( "<div>" ).css( "height", 100 )[ 0 ], var testElement = jQuery( "<div>" ).css( "height", 100 )[ 0 ],
testOptions = { duration: 100 }, testOptions = { duration: 100 },
tween, easingSpy, eased; tween, easingSpy, eased;
tween = jQuery.Tween( testElement, testOptions, "height", 0 ); tween = jQuery.Tween( testElement, testOptions, "height", 0 );
equal( tween.elem, testElement, "Sets .element" ); assert.equal( tween.elem, testElement, "Sets .element" );
equal( tween.options, testOptions, "sets .options" ); assert.equal( tween.options, testOptions, "sets .options" );
equal( tween.prop, "height", "sets .prop" ); assert.equal( tween.prop, "height", "sets .prop" );
equal( tween.end, 0, "sets .end" ); assert.equal( tween.end, 0, "sets .end" );
equal( tween.easing, jQuery.easing._default, "sets .easing to default when not provided" ); assert.equal(
equal( tween.unit, "px", "sets .unit to px when not provided" ); tween.easing,
jQuery.easing._default,
"sets .easing to default when not provided"
);
assert.equal( tween.unit, "px", "sets .unit to px when not provided" );
equal( tween.start, 100, "Reads .start value during construction" ); assert.equal( tween.start, 100, "Reads .start value during construction" );
equal( tween.now, 100, "Reads .now value during construction" ); assert.equal( tween.now, 100, "Reads .now value during construction" );
easingSpy = this.sandbox.spy( jQuery.easing, "swing" ); easingSpy = this.sandbox.spy( jQuery.easing, "swing" );
equal( tween.run( 0.1 ), tween, ".run() returns this" ); assert.equal( tween.run( 0.1 ), tween, ".run() returns this" );
equal( tween.pos, jQuery.easing.swing( 0.1 ), "set .pos" ); assert.equal( tween.pos, jQuery.easing.swing( 0.1 ), "set .pos" );
eased = 100 - ( jQuery.easing.swing( 0.1 ) * 100 ); eased = 100 - ( jQuery.easing.swing( 0.1 ) * 100 );
equal( tween.now, eased, "Calculated tween" ); assert.equal( tween.now, eased, "Calculated tween" );
ok( easingSpy.calledWith( 0.1, 0.1 * testOptions.duration, 0, 1, testOptions.duration ), assert.ok(
"...using jQuery.easing.linear with back-compat arguments" ); easingSpy.calledWith( 0.1, 0.1 * testOptions.duration, 0, 1, testOptions.duration ),
equal( parseFloat( testElement.style.height ).toFixed( 2 ), eased.toFixed( 2 ), "Set value" ); "...using jQuery.easing.linear with back-compat arguments"
);
assert.equal(
parseFloat( testElement.style.height ).toFixed( 2 ),
eased.toFixed( 2 ), "Set value"
);
tween.run( 1 ); tween.run( 1 );
equal( testElement.style.height, "0px", "Checking another value" ); assert.equal( testElement.style.height, "0px", "Checking another value" );
tween.run( 0 ); tween.run( 0 );
equal( testElement.style.height, "100px", "Can even go back in time" ); assert.equal( testElement.style.height, "100px", "Can even go back in time" );
} ); } );
test( "jQuery.Tween - No duration", function() { QUnit.test( "jQuery.Tween - No duration", function( assert ) {
expect( 3 ); assert.expect( 3 );
var testObject = { test: 100 }, var testObject = { test: 100 },
testOptions = { duration: 0 }, testOptions = { duration: 0 },
@ -218,13 +227,13 @@ test( "jQuery.Tween - No duration", function() {
easingSpy = this.sandbox.spy( jQuery.easing, "swing" ); easingSpy = this.sandbox.spy( jQuery.easing, "swing" );
tween.run( 0.5 ); tween.run( 0.5 );
equal( tween.pos, 0.5, "set .pos correctly" ); assert.equal( tween.pos, 0.5, "set .pos correctly" );
equal( testObject.test, 50, "set value on object correctly" ); assert.equal( testObject.test, 50, "set value on object correctly" );
equal( easingSpy.callCount, 0, "didn't ease the value" ); assert.equal( easingSpy.callCount, 0, "didn't ease the value" );
} ); } );
test( "jQuery.Tween - step function option", function() { QUnit.test( "jQuery.Tween - step function option", function( assert ) {
expect( 4 ); assert.expect( 4 );
var testObject = { test: 100 }, var testObject = { test: 100 },
testOptions = { duration: 100, step: this.sandbox.spy() }, testOptions = { duration: 100, step: this.sandbox.spy() },
@ -233,20 +242,26 @@ test( "jQuery.Tween - step function option", function() {
propHookSpy = this.sandbox.spy( jQuery.Tween.propHooks._default, "set" ); propHookSpy = this.sandbox.spy( jQuery.Tween.propHooks._default, "set" );
tween = jQuery.Tween( testObject, testOptions, "test", 0, "linear" ); tween = jQuery.Tween( testObject, testOptions, "test", 0, "linear" );
equal( testOptions.step.callCount, 0, "didn't call step on create" ); assert.equal( testOptions.step.callCount, 0, "didn't call step on create" );
tween.run( 0.5 ); tween.run( 0.5 );
ok( testOptions.step.calledOn( testObject ), assert.ok(
"Called step function in context of animated object" ); testOptions.step.calledOn( testObject ),
ok( testOptions.step.calledWith( 50, tween ), "Called step function with correct parameters" ); "Called step function in context of animated object"
);
ok( testOptions.step.calledBefore( propHookSpy ), assert.ok(
"Called step function before calling propHook.set" ); testOptions.step.calledWith( 50, tween ),
"Called step function with correct parameters"
);
assert.ok(
testOptions.step.calledBefore( propHookSpy ),
"Called step function before calling propHook.set"
);
} ); } );
test( "jQuery.Tween - custom propHooks", function() { QUnit.test( "jQuery.Tween - custom propHooks", function( assert ) {
expect( 3 ); assert.expect( 3 );
var testObject = {}, var testObject = {},
testOptions = { duration: 100, step: this.sandbox.spy() }, testOptions = { duration: 100, step: this.sandbox.spy() },
@ -259,17 +274,20 @@ test( "jQuery.Tween - custom propHooks", function() {
jQuery.Tween.propHooks.testHooked = propHook; jQuery.Tween.propHooks.testHooked = propHook;
tween = jQuery.Tween( testObject, testOptions, "testHooked", 0, "linear" ); tween = jQuery.Tween( testObject, testOptions, "testHooked", 0, "linear" );
ok( propHook.get.calledWith( tween ), "called propHook.get on create" ); assert.ok( propHook.get.calledWith( tween ), "called propHook.get on create" );
equal( tween.now, 100, "Used return value from propHook.get" ); assert.equal( tween.now, 100, "Used return value from propHook.get" );
tween.run( 0.5 ); tween.run( 0.5 );
ok( propHook.set.calledWith( tween ), "Called propHook.set function with correct parameters" ); assert.ok(
propHook.set.calledWith( tween ),
"Called propHook.set function with correct parameters"
);
delete jQuery.Tween.propHooks.testHooked; delete jQuery.Tween.propHooks.testHooked;
} ); } );
test( "jQuery.Tween - custom propHooks - advanced values", function() { QUnit.test( "jQuery.Tween - custom propHooks - advanced values", function( assert ) {
expect( 5 ); assert.expect( 5 );
var testObject = {}, var testObject = {},
testOptions = { duration: 100, step: this.sandbox.spy() }, testOptions = { duration: 100, step: this.sandbox.spy() },
@ -282,15 +300,18 @@ test( "jQuery.Tween - custom propHooks - advanced values", function() {
jQuery.Tween.propHooks.testHooked = propHook; jQuery.Tween.propHooks.testHooked = propHook;
tween = jQuery.Tween( testObject, testOptions, "testHooked", [ 1, 1 ], "linear" ); tween = jQuery.Tween( testObject, testOptions, "testHooked", [ 1, 1 ], "linear" );
ok( propHook.get.calledWith( tween ), "called propHook.get on create" ); assert.ok( propHook.get.calledWith( tween ), "called propHook.get on create" );
deepEqual( tween.start, [ 0, 0 ], "Used return value from get" ); assert.deepEqual( tween.start, [ 0, 0 ], "Used return value from get" );
tween.run( 0.5 ); tween.run( 0.5 );
// Some day this NaN assumption might change - perhaps add a "calc" helper to the hooks? // Some day this NaN assumption might change - perhaps add a "calc" helper to the hooks?
ok( isNaN( tween.now ), "Used return value from propHook.get" ); assert.ok( isNaN( tween.now ), "Used return value from propHook.get" );
equal( tween.pos, 0.5, "But the eased percent is still available" ); assert.equal( tween.pos, 0.5, "But the eased percent is still available" );
ok( propHook.set.calledWith( tween ), "Called propHook.set function with correct parameters" ); assert.ok(
propHook.set.calledWith( tween ),
"Called propHook.set function with correct parameters"
);
delete jQuery.Tween.propHooks.testHooked; delete jQuery.Tween.propHooks.testHooked;
} ); } );

View File

@ -4,7 +4,7 @@ if ( !jQuery.fn.wrap ) { // no wrap module
return; return;
} }
module( "wrap", { QUnit.module( "wrap", {
teardown: moduleTeardown teardown: moduleTeardown
}); });
@ -19,36 +19,36 @@ function manipulationFunctionReturningObj( value ) {
}; };
} }
function testWrap( val ) { function testWrap( val , assert ) {
expect( 19 ); assert.expect( 19 );
var defaultText, result, j, i, cacheLength; var defaultText, result, j, i, cacheLength;
defaultText = "Try them out:"; defaultText = "Try them out:";
result = jQuery("#first").wrap( val("<div class='red'><span></span></div>") ).text(); result = jQuery("#first").wrap( val("<div class='red'><span></span></div>") ).text();
equal( defaultText, result, "Check for wrapping of on-the-fly html" ); assert.equal( defaultText, result, "Check for wrapping of on-the-fly html" );
ok( jQuery("#first").parent().parent().is(".red"), "Check if wrapper has class 'red'" ); assert.ok( jQuery("#first").parent().parent().is(".red"), "Check if wrapper has class 'red'" );
result = jQuery("#first").wrap( val(document.getElementById("empty")) ).parent(); result = jQuery("#first").wrap( val(document.getElementById("empty")) ).parent();
ok( result.is("ol"), "Check for element wrapping" ); assert.ok( result.is("ol"), "Check for element wrapping" );
equal( result.text(), defaultText, "Check for element wrapping" ); assert.equal( result.text(), defaultText, "Check for element wrapping" );
jQuery("#check1").on( "click", function() { jQuery("#check1").on( "click", function() {
var checkbox = this; var checkbox = this;
ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" ); assert.ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
jQuery( checkbox ).wrap( val("<div id='c1' style='display:none;'></div>") ); jQuery( checkbox ).wrap( val("<div id='c1' style='display:none;'></div>") );
ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" ); assert.ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
}).prop( "checked", false )[ 0 ].click(); }).prop( "checked", false )[ 0 ].click();
// using contents will get comments regular, text, and comment nodes // using contents will get comments regular, text, and comment nodes
j = jQuery("#nonnodes").contents(); j = jQuery("#nonnodes").contents();
j.wrap( val("<i></i>") ); j.wrap( val("<i></i>") );
equal( jQuery("#nonnodes > i").length, jQuery("#nonnodes")[ 0 ].childNodes.length, "Check node,textnode,comment wraps ok" ); assert.equal( jQuery("#nonnodes > i").length, jQuery("#nonnodes")[ 0 ].childNodes.length, "Check node,textnode,comment wraps ok" );
equal( jQuery("#nonnodes > i").text(), j.text(), "Check node,textnode,comment wraps doesn't hurt text" ); assert.equal( jQuery("#nonnodes > i").text(), j.text(), "Check node,textnode,comment wraps doesn't hurt text" );
// Try wrapping a disconnected node // Try wrapping a disconnected node
cacheLength = 0; cacheLength = 0;
@ -57,32 +57,32 @@ function testWrap( val ) {
} }
j = jQuery("<label/>").wrap( val("<li/>") ); j = jQuery("<label/>").wrap( val("<li/>") );
equal( j[ 0 ] .nodeName.toUpperCase(), "LABEL", "Element is a label" ); assert.equal( j[ 0 ] .nodeName.toUpperCase(), "LABEL", "Element is a label" );
equal( j[ 0 ].parentNode.nodeName.toUpperCase(), "LI", "Element has been wrapped" ); assert.equal( j[ 0 ].parentNode.nodeName.toUpperCase(), "LI", "Element has been wrapped" );
for ( i in jQuery.cache ) { for ( i in jQuery.cache ) {
cacheLength--; cacheLength--;
} }
equal( cacheLength, 0, "No memory leak in jQuery.cache (bug #7165)" ); assert.equal( cacheLength, 0, "No memory leak in jQuery.cache (bug #7165)" );
// Wrap an element containing a text node // Wrap an element containing a text node
j = jQuery("<span/>").wrap("<div>test</div>"); j = jQuery("<span/>").wrap("<div>test</div>");
equal( j[ 0 ].previousSibling.nodeType, 3, "Make sure the previous node is a text element" ); assert.equal( j[ 0 ].previousSibling.nodeType, 3, "Make sure the previous node is a text element" );
equal( j[ 0 ].parentNode.nodeName.toUpperCase(), "DIV", "And that we're in the div element." ); assert.equal( j[ 0 ].parentNode.nodeName.toUpperCase(), "DIV", "And that we're in the div element." );
// Try to wrap an element with multiple elements (should fail) // Try to wrap an element with multiple elements (should fail)
j = jQuery("<div><span></span></div>").children().wrap("<p></p><div></div>"); j = jQuery("<div><span></span></div>").children().wrap("<p></p><div></div>");
equal( j[ 0 ].parentNode.parentNode.childNodes.length, 1, "There should only be one element wrapping." ); assert.equal( j[ 0 ].parentNode.parentNode.childNodes.length, 1, "There should only be one element wrapping." );
equal( j.length, 1, "There should only be one element (no cloning)." ); assert.equal( j.length, 1, "There should only be one element (no cloning)." );
equal( j[ 0 ].parentNode.nodeName.toUpperCase(), "P", "The span should be in the paragraph." ); assert.equal( j[ 0 ].parentNode.nodeName.toUpperCase(), "P", "The span should be in the paragraph." );
// Wrap an element with a jQuery set // Wrap an element with a jQuery set
j = jQuery("<span/>").wrap( jQuery("<div></div>") ); j = jQuery("<span/>").wrap( jQuery("<div></div>") );
equal( j[ 0 ].parentNode.nodeName.toLowerCase(), "div", "Wrapping works." ); assert.equal( j[ 0 ].parentNode.nodeName.toLowerCase(), "div", "Wrapping works." );
// Wrap an element with a jQuery set and event // Wrap an element with a jQuery set and event
result = jQuery("<div></div>").on( "click", function() { result = jQuery("<div></div>").on( "click", function() {
ok( true, "Event triggered." ); assert.ok( true, "Event triggered." );
// Remove handlers on detached elements // Remove handlers on detached elements
result.off(); result.off();
@ -90,49 +90,49 @@ function testWrap( val ) {
}); });
j = jQuery("<span/>").wrap( result ); j = jQuery("<span/>").wrap( result );
equal( j[ 0 ].parentNode.nodeName.toLowerCase(), "div", "Wrapping works." ); assert.equal( j[ 0 ].parentNode.nodeName.toLowerCase(), "div", "Wrapping works." );
j.parent().trigger("click"); j.parent().trigger("click");
} }
test( "wrap(String|Element)", function() { QUnit.test( "wrap(String|Element)", function( assert ) {
testWrap( manipulationBareObj ); testWrap( manipulationBareObj, assert );
}); });
test( "wrap(Function)", function() { QUnit.test( "wrap(Function)", function( assert ) {
testWrap( manipulationFunctionReturningObj ); testWrap( manipulationFunctionReturningObj, assert );
}); });
test( "wrap(Function) with index (#10177)", function() { QUnit.test( "wrap(Function) with index (#10177)", function( assert ) {
var expectedIndex = 0, var expectedIndex = 0,
targets = jQuery("#qunit-fixture p"); targets = jQuery("#qunit-fixture p");
expect( targets.length ); assert.expect( targets.length );
targets.wrap(function(i) { targets.wrap(function(i) {
equal( i, expectedIndex, "Check if the provided index (" + i + ") is as expected (" + expectedIndex + ")" ); assert.equal( i, expectedIndex, "Check if the provided index (" + i + ") is as expected (" + expectedIndex + ")" );
expectedIndex++; expectedIndex++;
return "<div id='wrap_index_'" + i + "'></div>"; return "<div id='wrap_index_'" + i + "'></div>";
}); });
}); });
test( "wrap(String) consecutive elements (#10177)", function() { QUnit.test( "wrap(String) consecutive elements (#10177)", function( assert ) {
var targets = jQuery("#qunit-fixture p"); var targets = jQuery("#qunit-fixture p");
expect( targets.length * 2 ); assert.expect( targets.length * 2 );
targets.wrap("<div class='wrapper'></div>"); targets.wrap("<div class='wrapper'></div>");
targets.each(function() { targets.each(function() {
var $this = jQuery(this); var $this = jQuery(this);
ok( $this.parent().is(".wrapper"), "Check each elements parent is correct (.wrapper)" ); assert.ok( $this.parent().is(".wrapper"), "Check each elements parent is correct (.wrapper)" );
equal( $this.siblings().length, 0, "Each element should be wrapped individually" ); assert.equal( $this.siblings().length, 0, "Each element should be wrapped individually" );
}); });
}); });
test( "wrapAll(String)", function() { QUnit.test( "wrapAll(String)", function( assert ) {
expect( 5 ); assert.expect( 5 );
var prev, p, result; var prev, p, result;
@ -140,16 +140,16 @@ test( "wrapAll(String)", function() {
p = jQuery("#firstp,#first")[ 0 ].parentNode; p = jQuery("#firstp,#first")[ 0 ].parentNode;
result = jQuery("#firstp,#first").wrapAll( "<div class='red'><div class='tmp'></div></div>" ); result = jQuery("#firstp,#first").wrapAll( "<div class='red'><div class='tmp'></div></div>" );
equal( result.parent().length, 1, "Check for wrapping of on-the-fly html" ); assert.equal( result.parent().length, 1, "Check for wrapping of on-the-fly html" );
ok( jQuery("#first").parent().parent().is(".red"), "Check if wrapper has class 'red'" ); assert.ok( jQuery("#first").parent().parent().is(".red"), "Check if wrapper has class 'red'" );
ok( jQuery("#firstp").parent().parent().is(".red"), "Check if wrapper has class 'red'" ); assert.ok( jQuery("#firstp").parent().parent().is(".red"), "Check if wrapper has class 'red'" );
equal( jQuery("#first").parent().parent()[ 0 ].previousSibling, prev, "Correct Previous Sibling" ); assert.equal( jQuery("#first").parent().parent()[ 0 ].previousSibling, prev, "Correct Previous Sibling" );
equal( jQuery("#first").parent().parent()[ 0 ].parentNode, p, "Correct Parent" ); assert.equal( jQuery("#first").parent().parent()[ 0 ].parentNode, p, "Correct Parent" );
}); });
test( "wrapAll(Function)", function() { QUnit.test( "wrapAll(Function)", function( assert ) {
expect( 5 ); assert.expect( 5 );
var prev = jQuery( "#firstp" )[ 0 ].previousSibling, var prev = jQuery( "#firstp" )[ 0 ].previousSibling,
p = jQuery( "#firstp,#first" )[ 0 ].parentNode, p = jQuery( "#firstp,#first" )[ 0 ].parentNode,
@ -157,15 +157,15 @@ test( "wrapAll(Function)", function() {
return "<div class='red'><div class='tmp'></div></div>"; return "<div class='red'><div class='tmp'></div></div>";
}); });
equal( result.parent().length, 1, "Check for wrapping of on-the-fly html" ); assert.equal( result.parent().length, 1, "Check for wrapping of on-the-fly html" );
ok( jQuery( "#first" ).parent().parent().is( ".red" ), "Check if wrapper has class 'red'" ); assert.ok( jQuery( "#first" ).parent().parent().is( ".red" ), "Check if wrapper has class 'red'" );
ok( jQuery( "#firstp" ).parent().parent().is( ".red" ), "Check if wrapper has class 'red'" ); assert.ok( jQuery( "#firstp" ).parent().parent().is( ".red" ), "Check if wrapper has class 'red'" );
ok( jQuery( "#first" ).parent().parent().parent().is( p ), "Correct Parent" ); assert.ok( jQuery( "#first" ).parent().parent().parent().is( p ), "Correct Parent" );
strictEqual( jQuery( "#first" ).parent().parent()[ 0 ].previousSibling, prev, "Correct Previous Sibling" ); assert.strictEqual( jQuery( "#first" ).parent().parent()[ 0 ].previousSibling, prev, "Correct Previous Sibling" );
}); });
test( "wrapAll(Function) check execution characteristics", function() { QUnit.test( "wrapAll(Function) check execution characteristics", function( assert ) {
expect( 3 ); assert.expect( 3 );
var i = 0; var i = 0;
@ -174,69 +174,69 @@ test( "wrapAll(Function) check execution characteristics", function() {
return ""; return "";
}); });
ok( !i, "should not execute function argument if target element does not exist" ); assert.ok( !i, "should not execute function argument if target element does not exist" );
jQuery( "#firstp" ).wrapAll(function( index ) { jQuery( "#firstp" ).wrapAll(function( index ) {
strictEqual( this, jQuery( "#firstp" )[ 0 ], "context must be the first found element" ); assert.strictEqual( this, jQuery( "#firstp" )[ 0 ], "context must be the first found element" );
strictEqual( index, undefined, "index argument should not be included in function execution" ); assert.strictEqual( index, undefined, "index argument should not be included in function execution" );
}); });
}); });
test( "wrapAll(Element)", function() { QUnit.test( "wrapAll(Element)", function( assert ) {
expect( 3 ); assert.expect( 3 );
var prev, p; var prev, p;
prev = jQuery("#firstp")[ 0 ].previousSibling; prev = jQuery("#firstp")[ 0 ].previousSibling;
p = jQuery("#first")[ 0 ].parentNode; p = jQuery("#first")[ 0 ].parentNode;
jQuery("#firstp,#first").wrapAll( document.getElementById("empty") ); jQuery("#firstp,#first").wrapAll( document.getElementById("empty") );
equal( jQuery("#first").parent()[ 0 ], jQuery("#firstp").parent()[ 0 ], "Same Parent" ); assert.equal( jQuery("#first").parent()[ 0 ], jQuery("#firstp").parent()[ 0 ], "Same Parent" );
equal( jQuery("#first").parent()[ 0 ].previousSibling, prev, "Correct Previous Sibling" ); assert.equal( jQuery("#first").parent()[ 0 ].previousSibling, prev, "Correct Previous Sibling" );
equal( jQuery("#first").parent()[ 0 ].parentNode, p, "Correct Parent" ); assert.equal( jQuery("#first").parent()[ 0 ].parentNode, p, "Correct Parent" );
}); });
test( "wrapInner(String)", function() { QUnit.test( "wrapInner(String)", function( assert ) {
expect( 6 ); assert.expect( 6 );
var num; var num;
num = jQuery("#first").children().length; num = jQuery("#first").children().length;
jQuery("#first").wrapInner( "<div class='red'><div id='tmp'></div></div>" ); jQuery("#first").wrapInner( "<div class='red'><div id='tmp'></div></div>" );
equal( jQuery("#first").children().length, 1, "Only one child" ); assert.equal( jQuery("#first").children().length, 1, "Only one child" );
ok( jQuery("#first").children().is(".red"), "Verify Right Element" ); assert.ok( jQuery("#first").children().is(".red"), "Verify Right Element" );
equal( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" ); assert.equal( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" );
num = jQuery("#first").html("foo<div>test</div><div>test2</div>").children().length; num = jQuery("#first").html("foo<div>test</div><div>test2</div>").children().length;
jQuery("#first").wrapInner( "<div class='red'><div id='tmp'></div></div>" ); jQuery("#first").wrapInner( "<div class='red'><div id='tmp'></div></div>" );
equal( jQuery("#first").children().length, 1, "Only one child" ); assert.equal( jQuery("#first").children().length, 1, "Only one child" );
ok( jQuery("#first").children().is(".red"), "Verify Right Element" ); assert.ok( jQuery("#first").children().is(".red"), "Verify Right Element" );
equal( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" ); assert.equal( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" );
}); });
test( "wrapInner(Element)", function() { QUnit.test( "wrapInner(Element)", function( assert ) {
expect( 5 ); assert.expect( 5 );
var num, var num,
div = jQuery("<div/>"); div = jQuery("<div/>");
num = jQuery("#first").children().length; num = jQuery("#first").children().length;
jQuery("#first").wrapInner( document.getElementById("empty") ); jQuery("#first").wrapInner( document.getElementById("empty") );
equal( jQuery("#first").children().length, 1, "Only one child" ); assert.equal( jQuery("#first").children().length, 1, "Only one child" );
ok( jQuery("#first").children().is("#empty"), "Verify Right Element" ); assert.ok( jQuery("#first").children().is("#empty"), "Verify Right Element" );
equal( jQuery("#first").children().children().length, num, "Verify Elements Intact" ); assert.equal( jQuery("#first").children().children().length, num, "Verify Elements Intact" );
div.wrapInner( "<span></span>" ); div.wrapInner( "<span></span>" );
equal( div.children().length, 1, "The contents were wrapped." ); assert.equal( div.children().length, 1, "The contents were wrapped." );
equal( div.children()[ 0 ].nodeName.toLowerCase(), "span", "A span was inserted." ); assert.equal( div.children()[ 0 ].nodeName.toLowerCase(), "span", "A span was inserted." );
}); });
test( "wrapInner(Function) returns String", function() { QUnit.test( "wrapInner(Function) returns String", function( assert ) {
expect( 6 ); assert.expect( 6 );
var num, var num,
val = manipulationFunctionReturningObj; val = manipulationFunctionReturningObj;
@ -244,20 +244,20 @@ test( "wrapInner(Function) returns String", function() {
num = jQuery("#first").children().length; num = jQuery("#first").children().length;
jQuery("#first").wrapInner( val("<div class='red'><div id='tmp'></div></div>") ); jQuery("#first").wrapInner( val("<div class='red'><div id='tmp'></div></div>") );
equal( jQuery("#first").children().length, 1, "Only one child" ); assert.equal( jQuery("#first").children().length, 1, "Only one child" );
ok( jQuery("#first").children().is(".red"), "Verify Right Element" ); assert.ok( jQuery("#first").children().is(".red"), "Verify Right Element" );
equal( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" ); assert.equal( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" );
num = jQuery("#first").html("foo<div>test</div><div>test2</div>").children().length; num = jQuery("#first").html("foo<div>test</div><div>test2</div>").children().length;
jQuery("#first").wrapInner( val("<div class='red'><div id='tmp'></div></div>") ); jQuery("#first").wrapInner( val("<div class='red'><div id='tmp'></div></div>") );
equal( jQuery("#first").children().length, 1, "Only one child" ); assert.equal( jQuery("#first").children().length, 1, "Only one child" );
ok( jQuery("#first").children().is(".red"), "Verify Right Element" ); assert.ok( jQuery("#first").children().is(".red"), "Verify Right Element" );
equal( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" ); assert.equal( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" );
}); });
test( "wrapInner(Function) returns Element", function() { QUnit.test( "wrapInner(Function) returns Element", function( assert ) {
expect( 5 ); assert.expect( 5 );
var num, var num,
val = manipulationFunctionReturningObj, val = manipulationFunctionReturningObj,
@ -265,84 +265,84 @@ test( "wrapInner(Function) returns Element", function() {
num = jQuery("#first").children().length; num = jQuery("#first").children().length;
jQuery("#first").wrapInner( val(document.getElementById("empty")) ); jQuery("#first").wrapInner( val(document.getElementById("empty")) );
equal( jQuery("#first").children().length, 1, "Only one child" ); assert.equal( jQuery("#first").children().length, 1, "Only one child" );
ok( jQuery("#first").children().is("#empty"), "Verify Right Element" ); assert.ok( jQuery("#first").children().is("#empty"), "Verify Right Element" );
equal( jQuery("#first").children().children().length, num, "Verify Elements Intact" ); assert.equal( jQuery("#first").children().children().length, num, "Verify Elements Intact" );
div.wrapInner( val("<span></span>") ); div.wrapInner( val("<span></span>") );
equal( div.children().length, 1, "The contents were wrapped." ); assert.equal( div.children().length, 1, "The contents were wrapped." );
equal( div.children()[ 0 ].nodeName.toLowerCase(), "span", "A span was inserted." ); assert.equal( div.children()[ 0 ].nodeName.toLowerCase(), "span", "A span was inserted." );
}); });
test( "unwrap()", function() { QUnit.test( "unwrap()", function( assert ) {
expect( 9 ); assert.expect( 9 );
jQuery("body").append(" <div id='unwrap' style='display: none;'> <div id='unwrap1'> <span class='unwrap'>a</span> <span class='unwrap'>b</span> </div> <div id='unwrap2'> <span class='unwrap'>c</span> <span class='unwrap'>d</span> </div> <div id='unwrap3'> <b><span class='unwrap unwrap3'>e</span></b> <b><span class='unwrap unwrap3'>f</span></b> </div> </div>"); jQuery("body").append(" <div id='unwrap' style='display: none;'> <div id='unwrap1'> <span class='unwrap'>a</span> <span class='unwrap'>b</span> </div> <div id='unwrap2'> <span class='unwrap'>c</span> <span class='unwrap'>d</span> </div> <div id='unwrap3'> <b><span class='unwrap unwrap3'>e</span></b> <b><span class='unwrap unwrap3'>f</span></b> </div> </div>");
var abcd = jQuery("#unwrap1 > span, #unwrap2 > span").get(), var abcd = jQuery("#unwrap1 > span, #unwrap2 > span").get(),
abcdef = jQuery("#unwrap span").get(); abcdef = jQuery("#unwrap span").get();
equal( jQuery("#unwrap1 span").add("#unwrap2 span:first-child").unwrap().length, 3, "make #unwrap1 and #unwrap2 go away" ); assert.equal( jQuery("#unwrap1 span").add("#unwrap2 span:first-child").unwrap().length, 3, "make #unwrap1 and #unwrap2 go away" );
deepEqual( jQuery("#unwrap > span").get(), abcd, "all four spans should still exist" ); assert.deepEqual( jQuery("#unwrap > span").get(), abcd, "all four spans should still exist" );
deepEqual( jQuery("#unwrap3 span").unwrap().get(), jQuery("#unwrap3 > span").get(), "make all b in #unwrap3 go away" ); assert.deepEqual( jQuery("#unwrap3 span").unwrap().get(), jQuery("#unwrap3 > span").get(), "make all b in #unwrap3 go away" );
deepEqual( jQuery("#unwrap3 span").unwrap().get(), jQuery("#unwrap > span.unwrap3").get(), "make #unwrap3 go away" ); assert.deepEqual( jQuery("#unwrap3 span").unwrap().get(), jQuery("#unwrap > span.unwrap3").get(), "make #unwrap3 go away" );
deepEqual( jQuery("#unwrap").children().get(), abcdef, "#unwrap only contains 6 child spans" ); assert.deepEqual( jQuery("#unwrap").children().get(), abcdef, "#unwrap only contains 6 child spans" );
deepEqual( jQuery("#unwrap > span").unwrap().get(), jQuery("body > span.unwrap").get(), "make the 6 spans become children of body" ); assert.deepEqual( jQuery("#unwrap > span").unwrap().get(), jQuery("body > span.unwrap").get(), "make the 6 spans become children of body" );
deepEqual( jQuery("body > span.unwrap").unwrap().get(), jQuery("body > span.unwrap").get(), "can't unwrap children of body" ); assert.deepEqual( jQuery("body > span.unwrap").unwrap().get(), jQuery("body > span.unwrap").get(), "can't unwrap children of body" );
deepEqual( jQuery("body > span.unwrap").unwrap().get(), abcdef, "can't unwrap children of body" ); assert.deepEqual( jQuery("body > span.unwrap").unwrap().get(), abcdef, "can't unwrap children of body" );
deepEqual( jQuery("body > span.unwrap").get(), abcdef, "body contains 6 .unwrap child spans" ); assert.deepEqual( jQuery("body > span.unwrap").get(), abcdef, "body contains 6 .unwrap child spans" );
jQuery("body > span.unwrap").remove(); jQuery("body > span.unwrap").remove();
}); });
test( "unwrap( selector )", function() { QUnit.test( "unwrap( selector )", function( assert ) {
expect( 5 ); assert.expect( 5 );
jQuery( "body" ).append( " <div id='unwrap' style='display: none;'> <div id='unwrap1'> <span class='unwrap'>a</span> <span class='unwrap'>b</span> </div> <div id='unwrap2'> <span class='unwrap'>c</span> <span class='unwrap'>d</span> </div> </div>" ); jQuery( "body" ).append( " <div id='unwrap' style='display: none;'> <div id='unwrap1'> <span class='unwrap'>a</span> <span class='unwrap'>b</span> </div> <div id='unwrap2'> <span class='unwrap'>c</span> <span class='unwrap'>d</span> </div> </div>" );
// Shouldn't unwrap, no match // Shouldn't unwrap, no match
jQuery( "#unwrap1 span" ) .unwrap( "#unwrap2" ); jQuery( "#unwrap1 span" ) .unwrap( "#unwrap2" );
equal( jQuery("#unwrap1").length, 1, "still wrapped" ); assert.equal( jQuery("#unwrap1").length, 1, "still wrapped" );
// Shouldn't unwrap, no match // Shouldn't unwrap, no match
jQuery( "#unwrap1 span" ) .unwrap( "span" ); jQuery( "#unwrap1 span" ) .unwrap( "span" );
equal( jQuery("#unwrap1").length, 1, "still wrapped" ); assert.equal( jQuery("#unwrap1").length, 1, "still wrapped" );
// Unwraps // Unwraps
jQuery( "#unwrap1 span" ) .unwrap( "#unwrap1" ); jQuery( "#unwrap1 span" ) .unwrap( "#unwrap1" );
equal( jQuery("#unwrap1").length, 0, "unwrapped match" ); assert.equal( jQuery("#unwrap1").length, 0, "unwrapped match" );
// Check return values // Check return values
deepEqual( jQuery( "#unwrap2 span" ).get(), jQuery( "#unwrap2 span" ).unwrap( "quote" ).get(), "return on unmatched unwrap" ); assert.deepEqual( jQuery( "#unwrap2 span" ).get(), jQuery( "#unwrap2 span" ).unwrap( "quote" ).get(), "return on unmatched unwrap" );
deepEqual( jQuery( "#unwrap2 span" ).get(), jQuery( "#unwrap2 span" ).unwrap( "#unwrap2" ).get(), "return on matched unwrap" ); assert.deepEqual( jQuery( "#unwrap2 span" ).get(), jQuery( "#unwrap2 span" ).unwrap( "#unwrap2" ).get(), "return on matched unwrap" );
jQuery("body > span.unwrap").remove(); jQuery("body > span.unwrap").remove();
}); });
test( "jQuery(<tag>) & wrap[Inner/All]() handle unknown elems (#10667)", function() { QUnit.test( "jQuery(<tag>) & wrap[Inner/All]() handle unknown elems (#10667)", function( assert ) {
expect( 2 ); assert.expect( 2 );
var $wraptarget = jQuery( "<div id='wrap-target'>Target</div>" ).appendTo( "#qunit-fixture" ), var $wraptarget = jQuery( "<div id='wrap-target'>Target</div>" ).appendTo( "#qunit-fixture" ),
$section = jQuery( "<section>" ).appendTo( "#qunit-fixture" ); $section = jQuery( "<section>" ).appendTo( "#qunit-fixture" );
$wraptarget.wrapAll("<aside style='background-color:green'></aside>"); $wraptarget.wrapAll("<aside style='background-color:green'></aside>");
notEqual( $wraptarget.parent("aside").get( 0 ).style.backgroundColor, "transparent", "HTML5 elements created with wrapAll inherit styles" ); assert.notEqual( $wraptarget.parent("aside").get( 0 ).style.backgroundColor, "transparent", "HTML5 elements created with wrapAll inherit styles" );
notEqual( $section.get( 0 ).style.backgroundColor, "transparent", "HTML5 elements create with jQuery( string ) inherit styles" ); assert.notEqual( $section.get( 0 ).style.backgroundColor, "transparent", "HTML5 elements create with jQuery( string ) inherit styles" );
}); });
test( "wrapping scripts (#10470)", function() { QUnit.test( "wrapping scripts (#10470)", function( assert ) {
expect( 2 ); assert.expect( 2 );
var script = document.createElement("script"); var script = document.createElement("script");
script.text = script.textContent = "ok( !document.eval10470, 'script evaluated once' ); document.eval10470 = true;"; script.text = script.textContent = "ok( !document.eval10470, 'script evaluated once' ); document.eval10470 = true;";
@ -350,7 +350,7 @@ test( "wrapping scripts (#10470)", function() {
document.eval10470 = false; document.eval10470 = false;
jQuery("#qunit-fixture").empty()[0].appendChild( script ); jQuery("#qunit-fixture").empty()[0].appendChild( script );
jQuery("#qunit-fixture script").wrap("<b></b>"); jQuery("#qunit-fixture script").wrap("<b></b>");
strictEqual( script.parentNode, jQuery("#qunit-fixture > b")[ 0 ], "correctly wrapped" ); assert.strictEqual( script.parentNode, jQuery("#qunit-fixture > b")[ 0 ], "correctly wrapped" );
jQuery( script ).remove(); jQuery( script ).remove();
}); });