Skip to content

Commit

Permalink
array mapping wraps destination in an unwanted array wankdanker#49
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Switzer committed Oct 11, 2019
1 parent 6f3ce0c commit 7d8252d
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1626,12 +1626,12 @@ test('mapping - map and append full array to existing mapped array', function (t

var expect = {
'thing2' : [
[{a: 'a1', b: 'b1'}
{a: 'a1', b: 'b1'}
, {a: 'a2', b: 'b2'}
, {a: 'a3', b: 'b3'}],
[{a: 'a4', b: 'b4'}
, {a: 'a3', b: 'b3'}
, {a: 'a4', b: 'b4'}
, {a: 'a5', b: 'b5'}
, {a: 'a6', b: 'b6'}]
, {a: 'a6', b: 'b6'}
]
};

Expand Down Expand Up @@ -2173,5 +2173,32 @@ test('Make sure no objects are created without data #48', function (t) {
t.end();
});


test('1 array mapping wraps destination in an unwanted array #49', function (t) {
const src = {
foo: [{ bar: 4 }, { bar: 33 }],
bifoo: [{ bar: 77 }, { bar: 97 }]
};
const mapper = {
"foo[].bar": "[]+",
"bifoo[].bar": "[]+"
}
var expect = [4, 33, 77, 97];
var result = om(src, mapper);
t.deepEqual(result, expect);
t.end();
});
test('2 array mapping wraps destination in an unwanted array #49', function (t) {
const src = {
foo: [{ bar: 4 }, { bar: 33 }],
bifoo: [{ bar: 77 }, { bar: 97 }]
};
const mapper2 = {
"foo[].bar": "num[]+",
"bifoo[].bar": "num[]+"
}
var expect = {num: [4, 33, 77, 97] };
var result = om(src, mapper2);
t.deepEqual(result, expect);
t.end();
});

0 comments on commit 7d8252d

Please sign in to comment.