diff options
author | Scott González <scott.gonzalez@gmail.com> | 2012-04-18 22:36:15 -0400 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2012-04-18 22:36:15 -0400 |
commit | a28983086ee91b19200c47fadc6bc3ba58a0fcb9 (patch) | |
tree | 63cb0a513473836b603213f06a31611c6c453e82 | |
parent | cb8474af1dc099de9e08665c9d6cdc2cf5864203 (diff) | |
download | jquery-ui-a28983086ee91b19200c47fadc6bc3ba58a0fcb9.tar.gz jquery-ui-a28983086ee91b19200c47fadc6bc3ba58a0fcb9.zip |
Tests: Lint.
-rw-r--r-- | grunt.js | 26 | ||||
-rw-r--r-- | tests/unit/spinner/spinner_core.js | 6 | ||||
-rw-r--r-- | tests/unit/spinner/spinner_methods.js | 2 | ||||
-rw-r--r-- | tests/unit/spinner/spinner_options.js | 2 | ||||
-rw-r--r-- | tests/unit/subsuite.js | 13 | ||||
-rw-r--r-- | tests/unit/subsuiteRunner.js | 26 | ||||
-rw-r--r-- | tests/unit/swarminject.js | 2 | ||||
-rw-r--r-- | tests/unit/tabs/tabs_deprecated.js | 20 | ||||
-rw-r--r-- | tests/unit/tabs/tabs_methods.js | 10 | ||||
-rw-r--r-- | tests/unit/testsuite.js | 18 | ||||
-rw-r--r-- | tests/unit/tooltip/tooltip_methods.js | 10 | ||||
-rw-r--r-- | tests/unit/tooltip/tooltip_options.js | 11 | ||||
-rw-r--r-- | tests/unit/widget/widget_core.js | 70 | ||||
-rw-r--r-- | tests/unit/widget/widget_extend.js | 34 |
14 files changed, 141 insertions, 109 deletions
@@ -345,13 +345,31 @@ grunt.initConfig({ browser: true, jquery: true }, defaults ), + // TODO: don't create so many globals in tests globals: { + accordion_state: true, + asyncTest: true, + commonWidgetTests: true, + deepEqual: true, + dlg: true, + domEqual: true, + drag: true, + el: true, + equal: true, + expect: true, + Globalize: true, + menu_click: true, + menu_log: true, module: true, - test: true, ok: true, - equal: true, - deepEqual: true, - QUnit: true + QUnit: true, + spinner_simulateKeyDownUp: true, + start: true, + strictEqual: true, + stop: true, + tabs_state: true, + tabs_disabled: true, + test: true } } }; diff --git a/tests/unit/spinner/spinner_core.js b/tests/unit/spinner/spinner_core.js index e12d1af2f..e38b467a3 100644 --- a/tests/unit/spinner/spinner_core.js +++ b/tests/unit/spinner/spinner_core.js @@ -99,7 +99,7 @@ test( "mouse click on up button, increases value not greater than max", function min: 0 }), button = element.spinner( "widget" ).find( ".ui-spinner-down" ); - + button.trigger( "mousedown" ).trigger( "mouseup" ); equal( element.val(), 1 ); button.trigger( "mousedown" ).trigger( "mouseup" ); @@ -189,8 +189,8 @@ test( "don't clear invalid value on blur", function() { test( "precision", function() { expect( 2 ); - var element = $( "#spin" ).val( .05 ).spinner({ - step: .0001 + var element = $( "#spin" ).val( 0.05 ).spinner({ + step: 0.0001 }); element.spinner( "stepUp" ); equal( element.val(), "0.0501", "precision from step" ); diff --git a/tests/unit/spinner/spinner_methods.js b/tests/unit/spinner/spinner_methods.js index 9c82218e1..2cb3c849f 100644 --- a/tests/unit/spinner/spinner_methods.js +++ b/tests/unit/spinner/spinner_methods.js @@ -54,7 +54,7 @@ test( "disable", function() { test( "enable", function() { expect( 5 ); - var element = $( "#spin" ).val( 1 ).spinner({ disabled: true }) + var element = $( "#spin" ).val( 1 ).spinner({ disabled: true }), wrapper = element.spinner( "widget" ); ok( wrapper.hasClass( "ui-spinner-disabled" ), "before: wrapper has ui-spinner-disabled class" ); diff --git a/tests/unit/spinner/spinner_options.js b/tests/unit/spinner/spinner_options.js index cbad3f870..6f5090d3a 100644 --- a/tests/unit/spinner/spinner_options.js +++ b/tests/unit/spinner/spinner_options.js @@ -191,7 +191,7 @@ test( "min, string", function() { equal( element.spinner( "option", "min" ), -100, "option converted to number" ); element.spinner( "value", -1000 ); - equal( element.val(), "($100.00)", "min constrained in value method") + equal( element.val(), "($100.00)", "min constrained in value method" ); }); test( "step, 2", function() { diff --git a/tests/unit/subsuite.js b/tests/unit/subsuite.js index 03e8c9706..6f966590b 100644 --- a/tests/unit/subsuite.js +++ b/tests/unit/subsuite.js @@ -1,12 +1,11 @@ (function() { -var versions = [ "1.6", "1.6.1", "1.6.2", "1.6.3", "1.6.4", "1.7", "1.7.1", "1.7.2", "git" ]; - -var additionalTests = { - accordion: [ "accordion_deprecated.html" ], - position: [ "position_deprecated.html" ], - tabs: [ "tabs_deprecated.html" ] -}; +var versions = [ "1.6", "1.6.1", "1.6.2", "1.6.3", "1.6.4", "1.7", "1.7.1", "1.7.2", "git" ], + additionalTests = { + accordion: [ "accordion_deprecated.html" ], + position: [ "position_deprecated.html" ], + tabs: [ "tabs_deprecated.html" ] + }; window.testAllVersions = function( widget ) { QUnit.testSuites( $.map( diff --git a/tests/unit/subsuiteRunner.js b/tests/unit/subsuiteRunner.js index ddfccc7c1..2d6de2de1 100644 --- a/tests/unit/subsuiteRunner.js +++ b/tests/unit/subsuiteRunner.js @@ -4,13 +4,16 @@ var subsuiteFrame; QUnit.extend( QUnit, { testSuites: function( suites ) { + function generateSuite( suite ) { + asyncTest( suite, function() { + QUnit.runSuite( suite ); + }); + } + for ( var i = 0; i < suites.length; i++ ) { - (function( suite ) { - asyncTest( suite, function() { - QUnit.runSuite( suite ); - }); - }( suites[i] ) ); + generateSuite( suites[ i ] ); } + QUnit.done = function() { subsuiteFrame.style.display = "none"; }; @@ -23,10 +26,12 @@ QUnit.extend( QUnit, { testDone: function() { var current = QUnit.id( this.config.current.id ), - children = current.children; + children = current.children, + i = 0, + length = children.length; // undo the auto-expansion of failed tests - for ( var i = 0; i < children.length; i++ ) { + for ( ; i < length; i++ ) { if ( children[i].nodeName === "OL" ) { children[i].style.display = "none"; } @@ -34,10 +39,11 @@ QUnit.extend( QUnit, { }, runSuite: function( suite ) { - var body = document.getElementsByTagName( "body" )[0], - iframe = subsuiteFrame = document.createElement( "iframe" ), - iframeWin; + var iframeWin, + body = document.getElementsByTagName( "body" )[0], + iframe = document.createElement( "iframe" ); + subsuiteFrame = iframe; iframe.className = "qunit-subsuite"; body.appendChild( iframe ); diff --git a/tests/unit/swarminject.js b/tests/unit/swarminject.js index db69326ab..78d37ef46 100644 --- a/tests/unit/swarminject.js +++ b/tests/unit/swarminject.js @@ -5,5 +5,5 @@ if ( !url || url.indexOf("http") !== 0 ) { return; } - document.write("<scr" + "ipt src='http://swarm.jquery.org/js/inject.js?" + (new Date).getTime() + "'></scr" + "ipt>"); + document.write( "<scr" + "ipt src='http://swarm.jquery.org/js/inject.js?" + (new Date()).getTime() + "'></scr" + "ipt>" ); })(); diff --git a/tests/unit/tabs/tabs_deprecated.js b/tests/unit/tabs/tabs_deprecated.js index 80bc4a326..c8f0e2881 100644 --- a/tests/unit/tabs/tabs_deprecated.js +++ b/tests/unit/tabs/tabs_deprecated.js @@ -89,10 +89,11 @@ test( "tabTemplate + panelTemplate", function() { // defaults are tested in the add method test expect( 11 ); - var element = $( "#tabs2" ).tabs({ - tabTemplate: "<li class='customTab'><a href='http://example.com/#{href}'>#{label}</a></li>", - panelTemplate: "<div class='customPanel'></div>" - }); + var tab, anchor, + element = $( "#tabs2" ).tabs({ + tabTemplate: "<li class='customTab'><a href='http://example.com/#{href}'>#{label}</a></li>", + panelTemplate: "<div class='customPanel'></div>" + }); element.one( "tabsadd", function( event, ui ) { var anchor = $( ui.tab ); equal( ui.index, 5, "ui.index" ); @@ -103,8 +104,8 @@ test( "tabTemplate + panelTemplate", function() { ok( $( ui.panel ).hasClass( "customPanel" ), "panel custom class" ); }); element.tabs( "add", "#new", "New" ); - var tab = element.find( ".ui-tabs-nav li" ).last(), - anchor = tab.find( "a" ); + tab = element.find( ".ui-tabs-nav li" ).last(); + anchor = tab.find( "a" ); equal( tab.text(), "New", "label" ); ok( tab.hasClass( "customTab" ), "tab custom class" ); equal( anchor.attr( "href" ), "http://example.com/#new", "href" ); @@ -393,7 +394,8 @@ module( "tabs (deprecated): methods" ); test( "add", function() { expect( 27 ); - var element = $( "#tabs1" ).tabs(); + var tab, anchor, + element = $( "#tabs1" ).tabs(); tabs_state( element, 1, 0, 0 ); // add without index @@ -404,8 +406,8 @@ test( "add", function() { }); element.tabs( "add", "#new", "New" ); tabs_state( element, 1, 0, 0, 0 ); - var tab = element.find( ".ui-tabs-nav li" ).last(), - anchor = tab.find( "a" ); + tab = element.find( ".ui-tabs-nav li" ).last(); + anchor = tab.find( "a" ); equal( tab.text(), "New", "label" ); equal( anchor.attr( "href" ), "#new", "href" ); equal( anchor.attr( "aria-controls" ), "new", "aria-controls" ); diff --git a/tests/unit/tabs/tabs_methods.js b/tests/unit/tabs/tabs_methods.js index fee87db96..0a59ae302 100644 --- a/tests/unit/tabs/tabs_methods.js +++ b/tests/unit/tabs/tabs_methods.js @@ -167,9 +167,8 @@ asyncTest( "load", function() { element.one( "tabsload", function( event, ui ) { // TODO: remove wrapping in 2.0 var uiTab = $( ui.tab ), - uiPanel = $( ui.panel ); - - var tab = element.find( ".ui-tabs-nav a" ).eq( 3 ), + uiPanel = $( ui.panel ), + tab = element.find( ".ui-tabs-nav a" ).eq( 3 ), panelId = tab.attr( "aria-controls" ), panel = $( "#" + panelId ); @@ -215,9 +214,8 @@ asyncTest( "load", function() { element.one( "tabsload", function( event, ui ) { // TODO: remove wrapping in 2.0 var uiTab = $( ui.tab ), - uiPanel = $( ui.panel ); - - var tab = element.find( ".ui-tabs-nav a" ).eq( 3 ), + uiPanel = $( ui.panel ), + tab = element.find( ".ui-tabs-nav a" ).eq( 3 ), panelId = tab.attr( "aria-controls" ), panel = $( "#" + panelId ); diff --git a/tests/unit/testsuite.js b/tests/unit/testsuite.js index d37e27f7b..2ef6bf472 100644 --- a/tests/unit/testsuite.js +++ b/tests/unit/testsuite.js @@ -63,7 +63,7 @@ window.commonWidgetTests = function( widget, settings ) { test( "version", function() { ok( "version" in $.ui[ widget ].prototype, "version property exists" ); }); -} +}; /* * Experimental assertion for comparing DOM objects. @@ -72,20 +72,22 @@ window.commonWidgetTests = function( widget, settings ) { * Then compares the result using deepEqual. */ window.domEqual = function( selector, modifier, message ) { - var attributes = ["class", "role", "id", "tabIndex", "aria-activedescendant"]; + var expected, actual, + attributes = ["class", "role", "id", "tabIndex", "aria-activedescendant"]; function extract(value) { if (!value || !value.length) { QUnit.push( false, actual, expected, "domEqual failed, can't extract " + selector + ", message was: " + message ); return; } - var result = {}; + var children, + result = {}; result.nodeName = value[0].nodeName; $.each(attributes, function(index, attr) { result[attr] = value.prop(attr); }); result.children = []; - var children = value.children(); + children = value.children(); if (children.length) { children.each(function() { result.children.push(extract($(this))); @@ -95,11 +97,11 @@ window.domEqual = function( selector, modifier, message ) { } return result; } - var expected = extract($(selector)); - modifier($(selector)); + expected = extract( $( selector ) ); + modifier( $( selector ) ); - var actual = extract($(selector)); + actual = extract( $( selector ) ); QUnit.push( QUnit.equiv(actual, expected), actual, expected, message ); -} +}; }()); diff --git a/tests/unit/tooltip/tooltip_methods.js b/tests/unit/tooltip/tooltip_methods.js index 3e8256c50..eaab1c0d1 100644 --- a/tests/unit/tooltip/tooltip_methods.js +++ b/tests/unit/tooltip/tooltip_methods.js @@ -16,11 +16,12 @@ test( "destroy", function() { test( "open/close", function() { expect( 3 ); $.fx.off = true; - var element = $( "#tooltipped1" ).tooltip(); + var tooltip, + element = $( "#tooltipped1" ).tooltip(); equal( $( ".ui-tooltip" ).length, 0, "no tooltip on init" ); element.tooltip( "open" ); - var tooltip = $( "#" + element.attr( "aria-describedby" ) ); + tooltip = $( "#" + element.attr( "aria-describedby" ) ); ok( tooltip.is( ":visible" ) ); element.tooltip( "close" ); @@ -31,11 +32,12 @@ test( "open/close", function() { test( "enable/disable", function() { expect( 7 ); $.fx.off = true; - var element = $( "#tooltipped1" ).tooltip(); + var tooltip, + element = $( "#tooltipped1" ).tooltip(); equal( $( ".ui-tooltip" ).length, 0, "no tooltip on init" ); element.tooltip( "open" ); - var tooltip = $( "#" + element.attr( "aria-describedby" ) ); + tooltip = $( "#" + element.attr( "aria-describedby" ) ); ok( tooltip.is( ":visible" ) ); element.tooltip( "disable" ); diff --git a/tests/unit/tooltip/tooltip_options.js b/tests/unit/tooltip/tooltip_options.js index 42529e087..4f994f8de 100644 --- a/tests/unit/tooltip/tooltip_options.js +++ b/tests/unit/tooltip/tooltip_options.js @@ -45,11 +45,12 @@ asyncTest( "content: sync + async callback", function() { test( "items", function() { expect( 2 ); - var element = $( "#qunit-fixture" ).tooltip({ - items: "#fixture-span" - }); + var event, + element = $( "#qunit-fixture" ).tooltip({ + items: "#fixture-span" + }); - var event = $.Event( "mouseenter" ); + event = $.Event( "mouseenter" ); event.target = $( "#fixture-span" )[ 0 ]; element.tooltip( "open", event ); deepEqual( $( "#" + $( "#fixture-span" ).attr( "aria-describedby" ) ).text(), "title-text" ); @@ -63,7 +64,7 @@ test( "items", function() { }); test( "tooltipClass", function() { - expect( 1 ) + expect( 1 ); var element = $( "#tooltipped1" ).tooltip({ tooltipClass: "custom" }).tooltip( "open" ); diff --git a/tests/unit/widget/widget_core.js b/tests/unit/widget/widget_core.js index e104d4ae9..38495e282 100644 --- a/tests/unit/widget/widget_core.js +++ b/tests/unit/widget/widget_core.js @@ -84,7 +84,8 @@ test( "custom selector expression", function() { test( "jQuery usage", function() { expect( 16 ); - var shouldCreate = false; + var elem, instance, ret, bcInstance, + shouldCreate = false; $.widget( "ui.testWidget", { getterSetterVal: 5, @@ -113,22 +114,22 @@ test( "jQuery usage", function() { }); shouldCreate = true; - var elem = $( "<div>" ) + elem = $( "<div>" ) .bind( "testwidgetcreate", function() { ok( shouldCreate, "create event triggered on instantiation" ); }) .testWidget(); shouldCreate = false; - var instance = elem.data( "ui-testWidget" ); + instance = elem.data( "ui-testWidget" ); equal( typeof instance, "object", "instance stored in .data(pluginName)" ); equal( instance.element[0], elem[0], "element stored on widget" ); - var ret = elem.testWidget( "methodWithParams", "value1", "value2" ); + ret = elem.testWidget( "methodWithParams", "value1", "value2" ); equal( ret, elem, "jQuery object returned from method call" ); // 1.9 BC for #7810 // TODO remove - var bcInstance = elem.data("testWidget"); + bcInstance = elem.data("testWidget"); equal( typeof bcInstance, "object", "instance stored in .data(pluginName)" ); equal( bcInstance.element[0], elem[0], "element stored on widget" ); @@ -148,7 +149,8 @@ test( "jQuery usage", function() { test( "direct usage", function() { expect( 9 ); - var shouldCreate = false; + var elem, instance, ret, + shouldCreate = false; $.widget( "ui.testWidget", { getterSetterVal: 5, @@ -171,17 +173,17 @@ test( "direct usage", function() { } }); - var elem = $( "<div>" )[ 0 ]; + elem = $( "<div>" )[ 0 ]; shouldCreate = true; - var instance = new $.ui.testWidget( {}, elem ); + instance = new $.ui.testWidget( {}, elem ); shouldCreate = false; equal( $( elem ).data( "ui-testWidget" ), instance, "instance stored in .data(pluginName)" ); equal( instance.element[ 0 ], elem, "element stored on widget" ); - var ret = instance.methodWithParams( "value1", "value2" ); + ret = instance.methodWithParams( "value1", "value2" ); equal( ret, instance, "plugin returned from method call" ); ret = instance.getterSetterMethod(); @@ -439,11 +441,12 @@ test( ".option() - getter", function() { _create: function() {} }); - var div = $( "<div>" ).testWidget({ - foo: "bar", - baz: 5, - qux: [ "quux", "quuux" ] - }); + var options, + div = $( "<div>" ).testWidget({ + foo: "bar", + baz: 5, + qux: [ "quux", "quuux" ] + }); deepEqual( div.testWidget( "option", "x" ), null, "non-existent option" ); deepEqual( div.testWidget( "option", "foo"), "bar", "single option - string" ); @@ -451,7 +454,7 @@ test( ".option() - getter", function() { deepEqual( div.testWidget( "option", "qux"), [ "quux", "quuux" ], "single option - array" ); - var options = div.testWidget( "option" ); + options = div.testWidget( "option" ); deepEqual( options, { create: null, disabled: false, @@ -483,14 +486,15 @@ test( ".option() - deep option getter", function() { }); test( ".option() - delegate to ._setOptions()", function() { - var calls = []; + var div, + calls = []; $.widget( "ui.testWidget", { _create: function() {}, _setOptions: function( options ) { calls.push( options ); } }); - var div = $( "<div>" ).testWidget(); + div = $( "<div>" ).testWidget(); calls = []; div.testWidget( "option", "foo", "bar" ); @@ -506,7 +510,8 @@ test( ".option() - delegate to ._setOptions()", function() { }); test( ".option() - delegate to ._setOption()", function() { - var calls = []; + var div, + calls = []; $.widget( "ui.testWidget", { _create: function() {}, _setOption: function( key, val ) { @@ -516,7 +521,7 @@ test( ".option() - delegate to ._setOption()", function() { }); } }); - var div = $( "<div>" ).testWidget(); + div = $( "<div>" ).testWidget(); calls = []; div.testWidget( "option", "foo", "bar" ); @@ -603,7 +608,7 @@ test( ".widget() - overriden", function() { test( "._bind() to element (default)", function() { expect( 12 ); - var that; + var that, widget; $.widget( "ui.testWidget", { _create: function() { that = this; @@ -623,7 +628,7 @@ test( "._bind() to element (default)", function() { equal( "keydown", event.type ); } }); - var widget = $( "<div></div>" ) + widget = $( "<div></div>" ) .testWidget() .trigger( "keyup" ) .trigger( "keydown" ); @@ -643,7 +648,7 @@ test( "._bind() to element (default)", function() { test( "._bind() to descendent", function() { expect( 12 ); - var that; + var that, widget, descendant; $.widget( "ui.testWidget", { _create: function() { that = this; @@ -664,28 +669,28 @@ test( "._bind() to descendent", function() { } }); // trigger events on both widget and descendent to ensure that only descendent receives them - var widget = $( "<div><p><strong>hello</strong> world</p></div>" ) + widget = $( "<div><p><strong>hello</strong> world</p></div>" ) .testWidget() .trigger( "keyup" ) .trigger( "keydown" ); - var descendent = widget.find( "strong" ) + descendant = widget.find( "strong" ) .trigger( "keyup" ) .trigger( "keydown" ); widget .testWidget( "disable" ) .trigger( "keyup" ) .trigger( "keydown" ); - descendent + descendant .trigger( "keyup" ) .trigger( "keydown" ); widget .testWidget( "enable" ) .trigger( "keyup" ) .trigger( "keydown" ); - descendent + descendant .trigger( "keyup" ) .trigger( "keydown" ); - descendent + descendant .addClass( "ui-state-disabled" ) .trigger( "keyup" ) .trigger( "keydown" ); @@ -693,7 +698,7 @@ test( "._bind() to descendent", function() { .testWidget( "destroy" ) .trigger( "keyup" ) .trigger( "keydown" ); - descendent + descendant .trigger( "keyup" ) .trigger( "keydown" ); }); @@ -942,10 +947,10 @@ test( "._trigger() - array as ui", function() { qux: 5, quux: 20 } + }, + extra = { + bar: 5 }; - var extra = { - bar: 5 - }; this._trigger( "foo", null, [ ui, extra ] ); } }); @@ -983,8 +988,7 @@ test( "._trigger() - instance as element", function() { $.widget( "ui.testWidget", { defaultElement: null, testEvent: function() { - var ui = { foo: "bar" }; - this._trigger( "foo", null, ui ); + this._trigger( "foo", null, { foo: "bar" } ); } }); var instance = $.ui.testWidget({ diff --git a/tests/unit/widget/widget_extend.js b/tests/unit/widget/widget_extend.js index 90e686e18..36cd999dd 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" }, @@ -10,8 +12,7 @@ test( "$.widget.extend()", function() { deep2copy = { foo: { baz: true }, foo2: document }, deepmerged = { foo: { bar: true, baz: true }, foo2: document }, arr = [1, 2, 3], - nestedarray = { arr: arr }, - ret; + nestedarray = { arr: arr }; $.widget.extend( settings, options ); deepEqual( settings, merged, "Check if extended: settings must be extended" ); @@ -25,19 +26,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 +49,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 +61,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,7 +75,7 @@ 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" ); @@ -87,16 +87,16 @@ test( "$.widget.extend()", function() { 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" ); |