aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/widget
diff options
context:
space:
mode:
authorScott González <scott.gonzalez@gmail.com>2012-04-18 22:36:15 -0400
committerScott González <scott.gonzalez@gmail.com>2012-04-18 22:36:15 -0400
commita28983086ee91b19200c47fadc6bc3ba58a0fcb9 (patch)
tree63cb0a513473836b603213f06a31611c6c453e82 /tests/unit/widget
parentcb8474af1dc099de9e08665c9d6cdc2cf5864203 (diff)
downloadjquery-ui-a28983086ee91b19200c47fadc6bc3ba58a0fcb9.tar.gz
jquery-ui-a28983086ee91b19200c47fadc6bc3ba58a0fcb9.zip
Tests: Lint.
Diffstat (limited to 'tests/unit/widget')
-rw-r--r--tests/unit/widget/widget_core.js70
-rw-r--r--tests/unit/widget/widget_extend.js34
2 files changed, 54 insertions, 50 deletions
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" );