Skip to content

Commit fc5fab2

Browse files
committed
Widget: Clean up extend tests
1 parent 6411cdf commit fc5fab2

File tree

1 file changed

+31
-33
lines changed

1 file changed

+31
-33
lines changed

tests/unit/widget/widget_extend.js

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
test("$.widget.extend(Object, Object)", function() {
2-
expect(28);
2+
expect(26);
33

44
var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
55
options = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
@@ -11,83 +11,81 @@ test("$.widget.extend(Object, Object)", function() {
1111
deep2copy = { foo: { baz: true }, foo2: document },
1212
deepmerged = { foo: { bar: true, baz: true }, foo2: document },
1313
arr = [1, 2, 3],
14-
nestedarray = { arr: arr };
14+
nestedarray = { arr: arr },
15+
ret;
1516

1617
$.widget.extend(settings, options);
17-
same( settings, merged, "Check if extended: settings must be extended" );
18-
same( options, optionsCopy, "Check if not modified: options must not be modified" );
19-
$.widget.extend(settings, null, options);
20-
same( settings, merged, "Check if extended: settings must be extended" );
21-
same( options, optionsCopy, "Check if not modified: options must not be modified" );
18+
deepEqual( settings, merged, "Check if extended: settings must be extended" );
19+
deepEqual( options, optionsCopy, "Check if not modified: options must not be modified" );
2220

2321
$.widget.extend(deep1, deep2);
24-
same( deep1.foo, deepmerged.foo, "Check if foo: settings must be extended" );
25-
same( deep2.foo, deep2copy.foo, "Check if not deep2: options must not be modified" );
26-
equals( deep1.foo2, document, "Make sure that a deep clone was not attempted on the document" );
22+
deepEqual( deep1.foo, deepmerged.foo, "Check if foo: settings must be extended" );
23+
deepEqual( deep2.foo, deep2copy.foo, "Check if not deep2: options must not be modified" );
24+
equal( deep1.foo2, document, "Make sure that a deep clone was not attempted on the document" );
2725

28-
ok( $.widget.extend({}, nestedarray).arr === arr, "Don't clone arrays" );
26+
strictEqual( $.widget.extend({}, nestedarray).arr, arr, "Don't clone arrays" );
2927
ok( jQuery.isPlainObject( $.widget.extend({ arr: arr }, { arr: {} }).arr ), "Cloned object heve to be an plain object" );
3028

3129
var empty = {};
3230
var optionsWithLength = { foo: { length: -1 } };
3331
$.widget.extend(empty, optionsWithLength);
34-
same( empty.foo, optionsWithLength.foo, "The length property must copy correctly" );
32+
deepEqual( empty.foo, optionsWithLength.foo, "The length property must copy correctly" );
3533

3634
empty = {};
3735
var optionsWithDate = { foo: { date: new Date } };
3836
$.widget.extend(empty, optionsWithDate);
39-
same( empty.foo, optionsWithDate.foo, "Dates copy correctly" );
37+
deepEqual( empty.foo, optionsWithDate.foo, "Dates copy correctly" );
4038

4139
var myKlass = function() {};
4240
var customObject = new myKlass();
4341
var optionsWithCustomObject = { foo: { date: customObject } };
4442
empty = {};
4543
$.widget.extend(empty, optionsWithCustomObject);
46-
ok( empty.foo && empty.foo.date === customObject, "Custom objects copy correctly (no methods)" );
44+
strictEqual( empty.foo.date, customObject, "Custom objects copy correctly (no methods)" );
4745

4846
// Makes the class a little more realistic
4947
myKlass.prototype = { someMethod: function(){} };
5048
empty = {};
5149
$.widget.extend(empty, optionsWithCustomObject);
52-
ok( empty.foo && empty.foo.date === customObject, "Custom objects copy correctly" );
50+
strictEqual( empty.foo.date, customObject, "Custom objects copy correctly" );
5351

54-
var ret = $.widget.extend({ foo: 4 }, { foo: new Number(5) } );
55-
ok( ret.foo == 5, "Wrapped numbers copy correctly" );
52+
ret = $.widget.extend({ foo: 4 }, { foo: new Number(5) } );
53+
equal( ret.foo, 5, "Wrapped numbers copy correctly" );
5654

5755
var nullUndef;
5856
nullUndef = $.widget.extend({}, options, { xnumber2: null });
59-
ok( nullUndef.xnumber2 === null, "Check to make sure null values are copied");
57+
strictEqual( nullUndef.xnumber2, null, "Check to make sure null values are copied");
6058

6159
nullUndef = $.widget.extend({}, options, { xnumber2: undefined });
62-
ok( nullUndef.xnumber2 === options.xnumber2, "Check to make sure undefined values are not copied");
60+
strictEqual( nullUndef.xnumber2, options.xnumber2, "Check to make sure undefined values are not copied");
6361

6462
nullUndef = $.widget.extend({}, options, { xnumber0: null });
65-
ok( nullUndef.xnumber0 === null, "Check to make sure null values are inserted");
63+
strictEqual( nullUndef.xnumber0, null, "Check to make sure null values are inserted");
6664

6765
// TODO weird test
6866
/*
6967
var target = {};
7068
var recursive = { foo:target, bar:5 };
7169
$.widget.extend(target, recursive);
72-
same( target, { bar:5 }, "Check to make sure a recursive obj doesn't go never-ending loop by not copying it over" );
70+
deepEqual( target, { bar:5 }, "Check to make sure a recursive obj doesn't go never-ending loop by not copying it over" );
7371
*/
7472

75-
var ret = jQuery.extend(true, { foo: [] }, { foo: [0] } ); // 1907
76-
equals( ret.foo.length, 1, "Check to make sure a value with coersion 'false' copies over when necessary to fix #1907" );
73+
ret = jQuery.extend(true, { foo: [] }, { foo: [0] } ); // 1907
74+
equal( ret.foo.length, 1, "Check to make sure a value with coersion 'false' copies over when necessary to fix #1907" );
7775

78-
var ret = jQuery.extend(true, { foo: "1,2,3" }, { foo: [1, 2, 3] } );
79-
ok( typeof ret.foo != "string", "Check to make sure values equal with coersion (but not actually equal) overwrite correctly" );
76+
ret = jQuery.extend(true, { foo: "1,2,3" }, { foo: [1, 2, 3] } );
77+
notStrictEqual( typeof ret.foo, "string", "Check to make sure values equal with coersion (but not actually equal) overwrite correctly" );
8078

81-
var ret = jQuery.extend(true, { foo:"bar" }, { foo:null } );
82-
ok( typeof ret.foo !== "undefined", "Make sure a null value doesn't crash with deep extend, for #1908" );
79+
ret = jQuery.extend(true, { foo:"bar" }, { foo:null } );
80+
notStrictEqual( typeof ret.foo, "undefined", "Make sure a null value doesn't crash with deep extend, for #1908" );
8381

8482
var obj = { foo:null };
8583
jQuery.extend(true, obj, { foo:"notnull" } );
86-
equals( obj.foo, "notnull", "Make sure a null value can be overwritten" );
84+
equal( obj.foo, "notnull", "Make sure a null value can be overwritten" );
8785

8886
function func() {}
8987
jQuery.extend(func, { key: "value" } );
90-
equals( func.key, "value", "Verify a function can be extended" );
88+
equal( func.key, "value", "Verify a function can be extended" );
9189

9290
var defaults = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
9391
defaultsCopy = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
@@ -98,10 +96,10 @@ test("$.widget.extend(Object, Object)", function() {
9896
merged2 = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "xx", xxx: "newstringx" };
9997

10098
var settings = jQuery.extend({}, defaults, options1, options2);
101-
same( settings, merged2, "Check if extended: settings must be extended" );
102-
same( defaults, defaultsCopy, "Check if not modified: options1 must not be modified" );
103-
same( options1, options1Copy, "Check if not modified: options1 must not be modified" );
104-
same( options2, options2Copy, "Check if not modified: options2 must not be modified" );
99+
deepEqual( settings, merged2, "Check if extended: settings must be extended" );
100+
deepEqual( defaults, defaultsCopy, "Check if not modified: options1 must not be modified" );
101+
deepEqual( options1, options1Copy, "Check if not modified: options1 must not be modified" );
102+
deepEqual( options2, options2Copy, "Check if not modified: options2 must not be modified" );
105103

106104
var input = {
107105
key: [ 1, 2, 3 ]

0 commit comments

Comments
 (0)