Skip to content

Commit 9898b0f

Browse files
committed
test: add test for RegExp excludeKeys matching
1 parent fa8e33d commit 9898b0f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

test/json2csv.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,26 @@ export function runTests() {
578578
assert.equal(csv, updatedCsv);
579579
});
580580

581+
// Test case for #252
582+
it('should exclude a single key that matches a provided excludeKeys RegExp', () => {
583+
const updatedCsv = csvTestData.wildcardMatch.replace(',baz.array', ',baz.b').replace(',c', ',b');
584+
585+
const csv = json2csv(jsonTestData.wildcardMatch, {
586+
excludeKeys: [/array/],
587+
});
588+
assert.equal(csv, updatedCsv);
589+
});
590+
591+
// Test case for #252
592+
it('should exclude multiple keys that match a provided excludeKeys RegExp', () => {
593+
const updatedCsv = csvTestData.wildcardMatch.replace(',baz.a,baz.array', '').replace(',a,c', '');
594+
595+
const csv = json2csv(jsonTestData.wildcardMatch, {
596+
excludeKeys: [/baz/],
597+
});
598+
assert.equal(csv, updatedCsv);
599+
});
600+
581601
// Test case for #207
582602
it('should include the array indexes in CSV key headers if specified via the option', () => {
583603
const csv = json2csv(jsonTestData.arrayIndexesAsKeys, {

0 commit comments

Comments
 (0)