Skip to content

Commit 096413c

Browse files
[#39] null as forced default value
1 parent 564371f commit 096413c

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

test/test.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1720,3 +1720,57 @@ test('map array inside array to property', function (t) {
17201720
t.deepEqual(result, expect);
17211721
t.end();
17221722
});
1723+
1724+
test('do not map when a property not present in source and default is not given in map', function (t) {
1725+
var expect = {
1726+
mapThis: 'defaultVal',
1727+
mapThisToo: [ {
1728+
property: 'defaultVal',
1729+
subArray: [ { property: null } ]
1730+
} ],
1731+
other: 'otherVal'
1732+
};
1733+
1734+
var map = {
1735+
"doNotMapThis": {
1736+
"key": "doNotMapThis",
1737+
"transform": function(val) {
1738+
return "_" + val;
1739+
}
1740+
},
1741+
"doNotMapThisToo[].property": {
1742+
"key": "doNotMapThisToo[].property",
1743+
"transform": function(val) {
1744+
return "_" + val;
1745+
}
1746+
},
1747+
"doNotMapThisToo[].subArray[].property": {
1748+
"key": "doNotMapThisToo[].subArray[].property",
1749+
"transform": function(val) {
1750+
return "_" + val;
1751+
}
1752+
},
1753+
"mapThis": {
1754+
"key": "mapThis",
1755+
"default": "defaultVal"
1756+
},
1757+
"mapThisToo[].property": {
1758+
"key": "mapThisToo[].property",
1759+
"default": "defaultVal"
1760+
},
1761+
"mapThisToo[].subArray[].property": {
1762+
"key": "mapThisToo[].subArray[].property?",
1763+
"default": null
1764+
},
1765+
"other": "other"
1766+
};
1767+
1768+
var obj = {
1769+
"other": "otherVal"
1770+
};
1771+
1772+
var result = om(obj, map);
1773+
1774+
t.deepEqual(result, expect);
1775+
t.end();
1776+
});

0 commit comments

Comments
 (0)