-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests to add coverage for #214
- Loading branch information
1 parent
4484336
commit 5274a96
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); | ||
}); |