Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
John McEleney
/
casperjs
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
05931919
...
05931919c76a6183317398f5cf190fe72d751bc6
authored
2013-02-06 14:09:33 +0100
by
Thomas Rosenau
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Added tests for mergeObjects;
Fixed exception when add[p] or origin[p] was falsy
1 parent
8a9938ce
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
3 deletions
modules/utils.js
tests/suites/utils.js
modules/utils.js
View file @
0593191
...
...
@@ -533,8 +533,8 @@ exports.isWebPage = isWebPage;
function
mergeObjects
(
origin
,
add
)
{
"use strict"
;
for
(
var
p
in
add
)
{
if
(
add
[
p
].
constructor
===
Object
)
{
if
(
origin
.
hasOwnProperty
(
p
)
&&
origin
[
p
].
constructor
===
Object
)
{
if
(
add
[
p
]
&&
add
[
p
]
.
constructor
===
Object
)
{
if
(
origin
[
p
]
&&
origin
[
p
].
constructor
===
Object
)
{
origin
[
p
]
=
mergeObjects
(
origin
[
p
],
add
[
p
]);
}
else
{
origin
[
p
]
=
clone
(
add
[
p
]);
...
...
tests/suites/utils.js
View file @
0593191
...
...
@@ -264,7 +264,7 @@ casper.test.begin('isJsFile() tests', 5, function(test) {
test
.
done
();
});
casper
.
test
.
begin
(
'mergeObjects() tests'
,
5
,
function
(
test
)
{
casper
.
test
.
begin
(
'mergeObjects() tests'
,
7
,
function
(
test
)
{
var
testCases
=
[
{
obj1
:
{
a
:
1
},
obj2
:
{
b
:
2
},
merged
:
{
a
:
1
,
b
:
2
}
...
...
@@ -273,6 +273,9 @@ casper.test.begin('mergeObjects() tests', 5, function(test) {
obj1
:
{},
obj2
:
{
a
:
1
},
merged
:
{
a
:
1
}
},
{
obj1
:
{},
obj2
:
{
a
:
{
b
:
2
}},
merged
:
{
a
:
{
b
:
2
}}
},
{
obj1
:
{
a
:
1
},
obj2
:
{},
merged
:
{
a
:
1
}
},
{
...
...
@@ -295,6 +298,12 @@ casper.test.begin('mergeObjects() tests', 5, function(test) {
'mergeObjects() can merge objects'
);
});
var
obj
=
{
x
:
1
};
var
merged1
=
utils
.
mergeObjects
({},
{
a
:
obj
});
var
merged2
=
utils
.
mergeObjects
({
a
:
{}},
{
a
:
obj
});
merged1
.
a
.
x
=
2
;
merged2
.
a
.
x
=
2
;
test
.
assertEquals
(
obj
.
x
,
1
,
'mergeObjects() creates deep clones'
);
test
.
done
();
});
...
...
Please
register
or
sign in
to post a comment