Skip to content

Commit 2bf617d

Browse files
committed
Added tests
1 parent ad606e8 commit 2bf617d

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"Value1"
2+
"abc"
3+
1234
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"Value1"
2+
"abc"
3+
"1234"

test/helpers/load-fixtures.js

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ var fixtures = [
2323
'embeddedjson',
2424
'flattenedEmbeddedJson',
2525
'fancyfields',
26+
'functionStringifyByDefault',
27+
'functionNoStringify',
2628
'trailingBackslash',
2729
'excelStrings',
2830
'overriddenDefaultValue',

test/index.js

+41
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,47 @@ async.parallel(loadFixtures(csvFixtures), function (err) {
408408
});
409409
});
410410

411+
test('function value should stringify results by default', function (t) {
412+
json2csv({
413+
data: [{
414+
value1: 'abc'
415+
}, {
416+
value1: '1234'
417+
}],
418+
fields: [{
419+
label: 'Value1',
420+
value: function (row) {
421+
return row.value1.toLocaleString();
422+
}
423+
}]
424+
}, function (error, csv) {
425+
t.error(error);
426+
t.equal(csv, csvFixtures.functionStringifyByDefault);
427+
t.end();
428+
});
429+
});
430+
431+
test('function value do not stringify', function (t) {
432+
json2csv({
433+
data: [{
434+
value1: '"abc"'
435+
}, {
436+
value1: '1234'
437+
}],
438+
fields: [{
439+
label: 'Value1',
440+
value: function (row) {
441+
return row.value1.toLocaleString();
442+
},
443+
stringify: false
444+
}]
445+
}, function (error, csv) {
446+
t.error(error);
447+
t.equal(csv, csvFixtures.functionNoStringify);
448+
t.end();
449+
});
450+
});
451+
411452
test('should parse JSON values with trailing backslashes', function (t) {
412453
json2csv({
413454
data: jsonTrailingBackslash,

0 commit comments

Comments
 (0)