Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
enver committed Jul 30, 2017
1 parent ad606e8 commit 2bf617d
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
3 changes: 3 additions & 0 deletions test/fixtures/csv/functionNoStringify.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"Value1"
"abc"
1234
3 changes: 3 additions & 0 deletions test/fixtures/csv/functionStringifyByDefault.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"Value1"
"abc"
"1234"
2 changes: 2 additions & 0 deletions test/helpers/load-fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ var fixtures = [
'embeddedjson',
'flattenedEmbeddedJson',
'fancyfields',
'functionStringifyByDefault',
'functionNoStringify',
'trailingBackslash',
'excelStrings',
'overriddenDefaultValue',
Expand Down
41 changes: 41 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,47 @@ async.parallel(loadFixtures(csvFixtures), function (err) {
});
});

test('function value should stringify results by default', function (t) {
json2csv({
data: [{
value1: 'abc'
}, {
value1: '1234'
}],
fields: [{
label: 'Value1',
value: function (row) {
return row.value1.toLocaleString();
}
}]
}, function (error, csv) {
t.error(error);
t.equal(csv, csvFixtures.functionStringifyByDefault);
t.end();
});
});

test('function value do not stringify', function (t) {
json2csv({
data: [{
value1: '"abc"'
}, {
value1: '1234'
}],
fields: [{
label: 'Value1',
value: function (row) {
return row.value1.toLocaleString();
},
stringify: false
}]
}, function (error, csv) {
t.error(error);
t.equal(csv, csvFixtures.functionNoStringify);
t.end();
});
});

test('should parse JSON values with trailing backslashes', function (t) {
json2csv({
data: jsonTrailingBackslash,
Expand Down

0 comments on commit 2bf617d

Please sign in to comment.