0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-29 23:16:30 +01:00
nodejs/test/simple/test-process-mixin.js
Felix Geisendörfer 55ab9b4541 Bug fix for deep process.mixin array handling
process.mixin was throwing an exception when trying to do a deep copy
of an object that included an array.

This bug was introduced in: 3bb7ad6fea
2010-03-01 14:13:57 -08:00

46 lines
1.3 KiB
JavaScript

process.mixin(require("../common"));
var target = function() {};
process.mixin(target, {
foo: 'bar'
});
assert.equal('bar', target.foo);
// This test verifies there are no DOM-related aspects to process.mixin which
// originally had been in there due to its jQuery origin.
var fakeDomElement = {deep: {nodeType: 4}};
target = {};
process.mixin(true, target, fakeDomElement);
assert.deepEqual(target.deep, fakeDomElement.deep);
var objectWithUndefinedValue = {foo: undefined};
target = {};
process.mixin(target, objectWithUndefinedValue);
assert.ok(target.hasOwnProperty('foo'));
// This test verifies getters and setters being copied correctly
var source = {
_foo:'a',
get foo(){ return this._foo; },
set foo(value){ this._foo = "did set to "+value; }
};
target = {};
process.mixin(target, source);
target._foo = 'b';
assert.equal(source.foo, 'a');
assert.equal('b', target.foo, 'target.foo != "b" -- value/result was copied instead of getter function');
source.foo = 'c';
assert.equal('did set to c', source.foo, 'source.foo != "c" -- value was set instead of calling setter function');
// Test that nested arrays are handled properly
target = {};
process.mixin(true, target, {
foo: ['bar'],
});
assert.notStrictEqual(['bar'], target.foo);
assert.deepEqual(['bar'], target.foo);