From e4bf6f465ddba82030e5b9725b5341556556efca Mon Sep 17 00:00:00 2001 From: David Worms Date: Mon, 3 Dec 2018 23:18:01 +0100 Subject: [PATCH] cast: group columns and error tests --- test/mocha.opts | 2 +- test/option.cast.coffee | 86 +++++++++++++++++++++-------------------- 2 files changed, 46 insertions(+), 42 deletions(-) diff --git a/test/mocha.opts b/test/mocha.opts index f4a4268..ae59bed 100644 --- a/test/mocha.opts +++ b/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 diff --git a/test/option.cast.coffee b/test/option.cast.coffee index d701f68..1cf74a8 100644 --- a/test/option.cast.coffee +++ b/test/option.cast.coffee @@ -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()