2010-02-25 07:36:17 +01:00
|
|
|
process.mixin(require("../common"));
|
2009-12-06 18:57:20 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
Fix bug in process.mixin where deep copies would not work at all.
Before, doing this:
var sys = require("sys");
var obj = {
one: 1,
two: 2,
three: {
value: 3
}
};
sys.p(process.mixin(true, {}, obj));
Would output this:
{
"two": 2,
"three": {
"one": 1,
"two": 2,
"three": {
"value": 3
},
"value": 3
},
"one": 1
}
When it should have outputed this:
{
"one": 1,
"two": 2,
"three": {
"value": 3
}
}
2010-02-22 07:47:15 +01:00
|
|
|
assert.deepEqual(target.deep, fakeDomElement.deep);
|
2009-12-06 19:02:55 +01:00
|
|
|
|
|
|
|
var objectWithUndefinedValue = {foo: undefined};
|
|
|
|
target = {};
|
|
|
|
|
|
|
|
process.mixin(target, objectWithUndefinedValue);
|
2010-02-18 17:50:48 +01:00
|
|
|
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; }
|
|
|
|
};
|
2010-03-01 16:05:28 +01:00
|
|
|
target = {};
|
2010-02-18 17:50:48 +01:00
|
|
|
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');
|
2010-03-01 16:05:28 +01:00
|
|
|
|
|
|
|
// Test that nested arrays are handled properly
|
|
|
|
target = {};
|
|
|
|
process.mixin(true, target, {
|
|
|
|
foo: ['bar'],
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.notStrictEqual(['bar'], target.foo);
|
|
|
|
assert.deepEqual(['bar'], target.foo);
|