Skip to content
This repository has been archived by the owner on Jun 28, 2021. It is now read-only.

Commit

Permalink
cast: group columns and error tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Dec 3, 2018
1 parent 873dd25 commit e4bf6f4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 42 deletions.
2 changes: 1 addition & 1 deletion test/mocha.opts
@@ -1,7 +1,7 @@
--throw-deprecation
--require should
--require ts-node/register
--require coffeescript/register
--require ts-node/register
--timeout 40000
--reporter spec
--recursive
86 changes: 45 additions & 41 deletions test/option.cast.coffee
Expand Up @@ -79,47 +79,51 @@ describe 'Option `cast`', ->
[ false, true ]
] unless err
next err

describe 'columns', ->

it 'header is true on first line when columns is true', (next) ->
parse """
a,b,c
1,2,3
4,5,6
""",
columns: true
cast: (value, context) ->
if context.header then value else parseInt value
, (err, records) ->
records.should.eql [
{a: 1, b: 2, c: 3}
{a: 4, b: 5, c: 6}
] unless err
next err
it 'header is true on first line when columns is true', (next) ->
parse """
a,b,c
1,2,3
4,5,6
""",
columns: true
cast: (value, context) ->
if context.header then value else parseInt value
, (err, records) ->
records.should.eql [
{a: 1, b: 2, c: 3}
{a: 4, b: 5, c: 6}
] unless err
next err

it 'header is false when columns is an object', (next) ->
parse """
1,2,3
4,5,6
""",
columns: ['a', 'b', 'c']
cast: (value, context) ->
context.header.should.be.false()
parseInt value
, (err, records) ->
records.should.eql [
{a: 1, b: 2, c: 3}
{a: 4, b: 5, c: 6}
] unless err
next err
it 'header is false when columns is an object', (next) ->
parse """
1,2,3
4,5,6
""",
columns: ['a', 'b', 'c']
cast: (value, context) ->
context.header.should.be.false()
parseInt value
, (err, records) ->
records.should.eql [
{a: 1, b: 2, c: 3}
{a: 4, b: 5, c: 6}
] unless err
next err

it 'catch error', (next) ->
parse """
1,2,3
4,5,6
""",
cast: (value, context) ->
if value is '6' then throw Error 'Catchme'
value
, (err, records) ->
err.message.should.eql 'Catchme'
next()
describe 'error', ->

it 'catch error', (next) ->
parse """
1,2,3
4,5,6
""",
cast: (value) ->
if value is '6' then throw Error 'Catchme'
value
, (err, records) ->
err.message.should.eql 'Catchme'
next()

0 comments on commit e4bf6f4

Please sign in to comment.