'use strict';

var jf = require('../../'),
    expect    = require('chai').expect,
    fs = require('fs');

let testPath = './' + Math.random() + '.json';
var testValue = { msg: Math.random().toString() };

let errorObj = { msg: 'intended error' }

describe('Error ', function () {
  it('should be handled in error listener', function (done) {

    jf.defaultEmitter.removeAllListeners('error');
    jf.defaultEmitter.on(
      'error',
      function(err){
        expect(err.innerError).to.eql(errorObj);
      }
    );

    jf.filed(null,
      function(err){
        expect(err.msg).to.eql('Failed to create path Iterator');
      }
    ).exec();

    jf.filed( testPath )
    .io(
      function( obj, filePath) {
        throw errorObj;//handled by listener of executer
      },
      function(err){
        expect(err.innerError).to.eql(errorObj);
      }
    ).filter(
      function(obj, filePath){
        throw errorObj; //handled by defaultEmitter
      }
    ).pass(
      function(obj, filePath, executer){
        executer.emit( 'error', errorObj ); //user can explicitly make executer to emit error
      },
      function(err){
        expect( err ).to.eql(errorObj);
        done();
      }
    ).exec();

  });

});

@@ -1224,12 +1224,1006 @@
 %0A  %7D);%0A%0A%7D);%0A
+%0A%0Alet testPath2 = './' + Math.random() + '.json';%0Adescribe('Error of link executer', function () %7B%0A  it('should be handled in error listener', function (done) %7B%0A%0A    jf.filed( testPath2 )%0A    .io(%0A      function( obj, filePath) %7B%0A        return %7B msg: 'Test value.' %7D;%0A      %7D%0A    ).link(%0A      function(obj, filePath, executer)%7B%0A        executer.emit('error', errorObj );%0A      %7D,%0A      function( err )%7B%0A        expect( err ).to.eql( errorObj );%0A        done();%0A      %7D%0A    ).exec();%0A%0A  %7D);%0A%0A%7D);%0A%0Alet testPath3 = './' + Math.random() + '.json';%0A%0Adescribe('Error of copy executer', function () %7B%0A  it('should be handled in error listener', function (done) %7B%0A%0A    jf.filed( testPath3 )%0A    .io(%0A      function( obj, filePath) %7B%0A        return %7B msg: 'Test value.' %7D;%0A      %7D%0A    ).copy(%0A      function(obj, filePath, executer)%7B%0A        executer.emit('error', errorObj );%0A      %7D,%0A      function( err )%7B%0A        expect( err ).to.eql( errorObj );%0A        done();%0A      %7D%0A    ).exec();%0A%0A  %7D);%0A%0A%7D);%0A

add some test case for testError.js