Skip to content

Commit

Permalink
Added tests to add coverage for #214
Browse files Browse the repository at this point in the history
  • Loading branch information
doug-martin committed Jul 10, 2019
1 parent 4484336 commit 5274a96
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/issues/issue214.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { EOL } from 'os';
import * as assert from 'assert';
import * as csv from '../../src';
import { RowMap } from '../../build/src/parser';


describe('Issue #214 - https://github.com/C2FO/fast-csv/issues/214', () => {
const CSV_CONTENT = [
'firstName,lastName,emailAddress',
'First1,Last1,[email protected]',
'First2,Last2,[email protected]',
'First3,Last3,[email protected]',
'First4,Last4,[email protected]',
].join(EOL);

const expectedRows = [
{ firstName: 'First1', lastName: 'Last1', emailAddress: '[email protected]' },
{ firstName: 'First2', lastName: 'Last2', emailAddress: '[email protected]' },
{ firstName: 'First3', lastName: 'Last3', emailAddress: '[email protected]' },
{ firstName: 'First4', lastName: 'Last4', emailAddress: '[email protected]' },
];

it('should emit data when using the on method', (next) => {
const rows: RowMap[] = [];
csv.parseString(CSV_CONTENT, { headers: true })
.on('data', (r: RowMap) => rows.push(r))
.on('error', next)
.on('end', (count: number) => {
assert.deepStrictEqual(rows, expectedRows);
next();
});
});

it('should emit data when using the addListener method', (next) => {
const rows: RowMap[] = [];
csv.parseString(CSV_CONTENT, { headers: true })
.addListener('data', (r: RowMap) => rows.push(r))
.on('error', next)
.on('end', (count: number) => {
assert.deepStrictEqual(rows, expectedRows);
next();
});
});
});

0 comments on commit 5274a96

Please sign in to comment.