|
282 | 282 | equal(_.clone(null), null, 'non objects should not be changed by clone'); |
283 | 283 | }); |
284 | 284 |
|
| 285 | + test('create', function() { |
| 286 | + var Parent = function() {}; |
| 287 | + Parent.prototype = {foo: function() {}, bar: 2}; |
| 288 | + |
| 289 | + _.each(['foo', null, undefined, 1], function(val) { |
| 290 | + deepEqual(_.create(val), {}, 'should return empty object when a non-object is provided'); |
| 291 | + }); |
| 292 | + |
| 293 | + ok(_.create([]) instanceof Array, 'should return new instance of array when array is provided'); |
| 294 | + |
| 295 | + var Child = function() {}; |
| 296 | + Child.prototype = _.create(Parent.prototype); |
| 297 | + ok(new Child instanceof Parent, 'object should inherit prototype'); |
| 298 | + |
| 299 | + var func = function() {}; |
| 300 | + Child.prototype = _.create(Parent.prototype, {func: func}); |
| 301 | + strictEqual(Child.prototype.func, func, 'properties should be added to object'); |
| 302 | + |
| 303 | + Child.prototype = _.create(Parent.prototype, {constructor: Child}); |
| 304 | + strictEqual(Child.prototype.constructor, Child); |
| 305 | + |
| 306 | + Child.prototype.foo = 'foo'; |
| 307 | + var created = _.create(Child.prototype, new Child); |
| 308 | + ok(!created.hasOwnProperty('foo'), 'should only add own properties'); |
| 309 | + }); |
| 310 | + |
285 | 311 | test('isEqual', function() { |
286 | 312 | function First() { |
287 | 313 | this.value = 1; |
|
0 commit comments