Skip to content

Commit

Permalink
fix: fix some issues in the AsyncParser tests
Browse files Browse the repository at this point in the history
  • Loading branch information
juanjoDiaz committed Jan 22, 2022
1 parent d476707 commit 695f116
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions test/JSON2CSVAsyncParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,17 @@ module.exports = (testRunner, jsonFixtures, csvFixtures, inMemoryJsonFixtures) =
});

testRunner.add('should hanlde array with nulls', async (t) => {
const input = new Readable();
input._read = () => {};
input.push('[null]');
input.push(null);
const opts = {
fields: ['carModel', 'price', 'color']
};
const parser = new AsyncParser(opts);

try {
const csv = await parser.parse([null]).promise();
const csv = await parser.parse(input).promise();
t.equal(csv, csvFixtures.emptyObject);
} catch(err) {
t.fail(err.message);
Expand Down Expand Up @@ -747,6 +751,10 @@ module.exports = (testRunner, jsonFixtures, csvFixtures, inMemoryJsonFixtures) =
});

testRunner.add('should parse data:[null] to csv with only column title, despite options.includeEmptyRows', async (t) => {
const input = new Readable();
input._read = () => {};
input.push('[null]');
input.push(null);
const opts = {
fields: ['carModel', 'price', 'color'],
includeEmptyRows: true,
Expand All @@ -755,7 +763,7 @@ module.exports = (testRunner, jsonFixtures, csvFixtures, inMemoryJsonFixtures) =
const parser = new AsyncParser(opts);

try {
const csv = await parser.parse([null]).promise();
const csv = await parser.parse(input).promise();
t.equal(csv, csvFixtures.emptyObject);
} catch(err) {
t.fail(err.message);
Expand Down Expand Up @@ -1252,7 +1260,6 @@ module.exports = (testRunner, jsonFixtures, csvFixtures, inMemoryJsonFixtures) =
t.end();
});


// String Escaping and preserving values

testRunner.add('should parse JSON values with trailing backslashes', async (t) => {
Expand Down

0 comments on commit 695f116

Please sign in to comment.