PageRenderTime 11ms CodeModel.GetById 2ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 1ms

/node_modules/csv/node_modules/stream-transform/test/error.coffee

https://github.com/matthewsklar/BookLoversUSA
CoffeeScript | 39 lines | 33 code | 5 blank | 1 comment | 2 complexity | b57856e89c0bd1e807db25682f0af484 MD5 | raw file
 1
 2should = require 'should'
 3generate = require 'csv-generate'
 4transform = if process.env.CSV_COV then require '../lib-cov' else require '../src'
 5
 6describe 'error', ->
 7
 8  it 'catch using stream api', (next) ->
 9      transformer = transform (row) ->
10        throw new Error 'Custom Error'
11      transformer.on 'error', (err) ->
12        err.message.should.eql 'Custom Error'
13        next()
14      transformer.on 'finish', ->
15        next new Error 'Should not be called'
16      transformer.write [ 'trigger' ]
17
18  it 'catch using pipe api', (next) ->
19      generator = generate length: 1000, objectMode: true, seed: 1, headers: 2
20      transformer = generator.pipe transform (row) ->
21        throw new Error 'Custom Error'
22      transformer.on 'error', (err) ->
23        err.message.should.eql 'Custom Error'
24        next()
25      transformer.on 'finish', ->
26        next new Error 'Should not be called'
27      transformer.write [ 'trigger' ]
28
29  it 'catch using callback api', (next) ->
30    transform [
31      [ '20322051544' ]
32      [ '28392898392' ]
33      [ '83929843999' ]
34    ], (row) ->
35      throw new Error 'Custom Error'
36    , (err, data) ->
37      # thrown multiple times for now
38      err.message.should.eql 'Custom Error'
39      next()