Skip to content

Commit d0ff411

Browse files
committed
test: add test cases for #244
1 parent f3189f1 commit d0ff411

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

test/json2csv.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,41 @@ export function runTests() {
478478
assert.equal(csv, updatedCsv);
479479
});
480480

481+
// Test case for #244
482+
it('should exclude a matched key prefix from the output when unwinding arrays', () => {
483+
const updatedCsv = csvTestData.unwind.replace(',data.options.name', '')
484+
.replace(/,MacBook (Pro|Air) \d+/g, '')
485+
.replace(/,(Super|Turbo)charger/g, '')
486+
.replace('5cf7ca3616c91100018844af,Computers\n', '')
487+
// Remove duplicate lines
488+
.replace('5cf7ca3616c91100018844bf,Cars\n', '');
489+
490+
const csv = json2csv(jsonTestData.unwind, {
491+
unwindArrays: true,
492+
expandArrayObjects: true,
493+
excludeKeys: ['data.options']
494+
});
495+
496+
assert.equal(csv, updatedCsv);
497+
});
498+
499+
// Test case for #244
500+
it('should exclude a matched key prefix from the output when unwinding arrays', () => {
501+
const updatedCsv = csvTestData.unwind.replace(',data.category,data.options.name', '')
502+
.replace(/,Computers,MacBook (Pro|Air) \d+/g, '')
503+
.replace(/,Cars,(Super|Turbo)charger/g, '')
504+
.replace('5cf7ca3616c91100018844af\n', '')
505+
// Remove duplicate lines
506+
.replace('5cf7ca3616c91100018844bf\n', '');
507+
508+
const csv = json2csv(jsonTestData.unwind, {
509+
unwindArrays: true,
510+
excludeKeys: ['data']
511+
});
512+
513+
assert.equal(csv, updatedCsv);
514+
});
515+
481516
it('should use a custom value parser function when provided', () => {
482517
const updatedCsv = csvTestData.trimmedFields.split('\n');
483518
const textRow = 'Parsed Value,Parsed Value,Parsed Value,Parsed Value,Parsed Value';

0 commit comments

Comments
 (0)