diff options
Diffstat (limited to 'tests/unit/widget/widget_extend.js')
-rw-r--r-- | tests/unit/widget/widget_extend.js | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/tests/unit/widget/widget_extend.js b/tests/unit/widget/widget_extend.js index 90e686e18..ae9855929 100644 --- a/tests/unit/widget/widget_extend.js +++ b/tests/unit/widget/widget_extend.js @@ -1,7 +1,9 @@ test( "$.widget.extend()", function() { expect( 26 ); - var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" }, + var ret, empty, optionsWithLength, optionsWithDate, myKlass, customObject, optionsWithCustomObject, nullUndef, + target, recursive, obj, input, output, + settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" }, options = { xnumber2: 1, xstring2: "x", xxx: "newstring" }, optionsCopy = { xnumber2: 1, xstring2: "x", xxx: "newstring" }, merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "x", xxx: "newstring" }, @@ -11,7 +13,13 @@ test( "$.widget.extend()", function() { deepmerged = { foo: { bar: true, baz: true }, foo2: document }, arr = [1, 2, 3], nestedarray = { arr: arr }, - ret; + defaults = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" }, + defaultsCopy = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" }, + options1 = { xnumber2: 1, xstring2: "x" }, + options1Copy = { xnumber2: 1, xstring2: "x" }, + options2 = { xstring2: "xx", xxx: "newstringx" }, + options2Copy = { xstring2: "xx", xxx: "newstringx" }, + merged2 = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "xx", xxx: "newstringx" }; $.widget.extend( settings, options ); deepEqual( settings, merged, "Check if extended: settings must be extended" ); @@ -25,19 +33,19 @@ test( "$.widget.extend()", function() { strictEqual( $.widget.extend({}, nestedarray).arr, arr, "Don't clone arrays" ); ok( $.isPlainObject( $.widget.extend({ arr: arr }, { arr: {} }).arr ), "Cloned object heve to be an plain object" ); - var empty = {}; - var optionsWithLength = { foo: { length: -1 } }; + empty = {}; + optionsWithLength = { foo: { length: -1 } }; $.widget.extend( empty, optionsWithLength ); deepEqual( empty.foo, optionsWithLength.foo, "The length property must copy correctly" ); empty = {}; - var optionsWithDate = { foo: { date: new Date } }; + optionsWithDate = { foo: { date: new Date() } }; $.widget.extend( empty, optionsWithDate ); deepEqual( empty.foo, optionsWithDate.foo, "Dates copy correctly" ); - var myKlass = function() {}; - var customObject = new myKlass(); - var optionsWithCustomObject = { foo: { date: customObject } }; + myKlass = function() {}; + customObject = new myKlass(); + optionsWithCustomObject = { foo: { date: customObject } }; empty = {}; $.widget.extend( empty, optionsWithCustomObject ); strictEqual( empty.foo.date, customObject, "Custom objects copy correctly (no methods)" ); @@ -48,10 +56,9 @@ test( "$.widget.extend()", function() { $.widget.extend( empty, optionsWithCustomObject ); strictEqual( empty.foo.date, customObject, "Custom objects copy correctly" ); - ret = $.widget.extend({ foo: 4 }, { foo: new Number(5) } ); + ret = $.widget.extend({ foo: 4 }, { foo: Number(5) } ); equal( ret.foo, 5, "Wrapped numbers copy correctly" ); - var nullUndef; nullUndef = $.widget.extend( {}, options, { xnumber2: null } ); strictEqual( nullUndef.xnumber2, null, "Check to make sure null values are copied"); @@ -61,8 +68,8 @@ test( "$.widget.extend()", function() { nullUndef = $.widget.extend( {}, options, { xnumber0: null } ); strictEqual( nullUndef.xnumber0, null, "Check to make sure null values are inserted"); - var target = {}; - var recursive = { foo:target, bar:5 }; + target = {}; + recursive = { foo:target, bar:5 }; $.widget.extend( target, recursive ); deepEqual( target, { foo: {}, bar: 5 }, "Check to make sure a recursive obj doesn't go never-ending loop by not copying it over" ); @@ -75,28 +82,20 @@ test( "$.widget.extend()", function() { ret = $.widget.extend( { foo:"bar" }, { foo:null } ); strictEqual( typeof ret.foo, "object", "Make sure a null value doesn't crash with deep extend, for #1908" ); - var obj = { foo:null }; + obj = { foo:null }; $.widget.extend( obj, { foo:"notnull" } ); equal( obj.foo, "notnull", "Make sure a null value can be overwritten" ); - var defaults = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" }, - defaultsCopy = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" }, - options1 = { xnumber2: 1, xstring2: "x" }, - options1Copy = { xnumber2: 1, xstring2: "x" }, - options2 = { xstring2: "xx", xxx: "newstringx" }, - options2Copy = { xstring2: "xx", xxx: "newstringx" }, - merged2 = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "xx", xxx: "newstringx" }; - - var settings = $.widget.extend( {}, defaults, options1, options2 ); + settings = $.widget.extend( {}, defaults, options1, options2 ); deepEqual( settings, merged2, "Check if extended: settings must be extended" ); deepEqual( defaults, defaultsCopy, "Check if not modified: options1 must not be modified" ); deepEqual( options1, options1Copy, "Check if not modified: options1 must not be modified" ); deepEqual( options2, options2Copy, "Check if not modified: options2 must not be modified" ); - var input = { + input = { key: [ 1, 2, 3 ] }; - var output = $.widget.extend( {}, input ); + output = $.widget.extend( {}, input ); deepEqual( input, output, "don't clone arrays" ); input.key[0] = 10; deepEqual( input, output, "don't clone arrays" ); |