Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/readString.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ReadStringConfig } from './model';

export function readString<T>(
csvString: string | typeof NODE_STREAM_INPUT,
config: ReadStringConfig<T> & {
config?: ReadStringConfig<T> & {
download?: false | undefined;
complete(results: ParseResult<T>): void;
},
Expand Down
33 changes: 29 additions & 4 deletions test/readString.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import expect from 'expect';
import { readString } from '../src/readString';

// eslint-disable-next-line no-undef
describe('readString', () => {
// eslint-disable-next-line no-undef
it('should return an array as expected', function () {
it('should return an array as expected', function() {
const fixtures = `Column 1,Column 2,Column 3,Column 4
1-1,1-2,1-3,1-4
2-1,2-2,2-3,2-4
Expand All @@ -19,10 +17,37 @@ describe('readString', () => {
];
readString(fixtures, {
worker: true,
complete: (results) => {
complete: (results: { data: string[][]; }) => {
expect(Array.isArray(results.data)).toBe(true);
expect(results.data).toEqual(expected);
},
});
});

it('should return an array as expected even without config', function() {
const fixtures = `Column 1,Column 2,Column 3,Column 4
1-1,1-2,1-3,1-4
2-1,2-2,2-3,2-4
3-1,3-2,3-3,3-4
4,5,6,7`;
const expected = {
"data": [
["Column 1", "Column 2", "Column 3", "Column 4"],
["1-1", "1-2", "1-3", "1-4"],
["2-1", "2-2", "2-3", "2-4"],
["3-1", "3-2", "3-3", "3-4"],
["4", "5", "6", "7"]
],
"errors": [],
"meta": {
"aborted": false,
"cursor": 91,
"delimiter": ",",
"linebreak": "\n",
"truncated": false
}
};
const result = readString(fixtures);
expect(result).toEqual(expected);
});
});