Skip to content

Commit

Permalink
[#39] null as forced default value
Browse files Browse the repository at this point in the history
  • Loading branch information
nagarajanchinnasamy committed Sep 25, 2017
1 parent 564371f commit 096413c
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1720,3 +1720,57 @@ test('map array inside array to property', function (t) {
t.deepEqual(result, expect);
t.end();
});

test('do not map when a property not present in source and default is not given in map', function (t) {
var expect = {
mapThis: 'defaultVal',
mapThisToo: [ {
property: 'defaultVal',
subArray: [ { property: null } ]
} ],
other: 'otherVal'
};

var map = {
"doNotMapThis": {
"key": "doNotMapThis",
"transform": function(val) {
return "_" + val;
}
},
"doNotMapThisToo[].property": {
"key": "doNotMapThisToo[].property",
"transform": function(val) {
return "_" + val;
}
},
"doNotMapThisToo[].subArray[].property": {
"key": "doNotMapThisToo[].subArray[].property",
"transform": function(val) {
return "_" + val;
}
},
"mapThis": {
"key": "mapThis",
"default": "defaultVal"
},
"mapThisToo[].property": {
"key": "mapThisToo[].property",
"default": "defaultVal"
},
"mapThisToo[].subArray[].property": {
"key": "mapThisToo[].subArray[].property?",
"default": null
},
"other": "other"
};

var obj = {
"other": "otherVal"
};

var result = om(obj, map);

t.deepEqual(result, expect);
t.end();
});

0 comments on commit 096413c

Please sign in to comment.