Skip to content

Commit

Permalink
test for multiple called back is added.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomohito Nakayama committed Mar 17, 2016
1 parent 51254ee commit d08a84a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/tools/testAll.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ mocha test/unit/testFilter.js
mocha test/unit/testError.js
mocha test/unit/testCalledback.js
mocha test/unit/testCalledback_more.js
mocha test/unit/testCalledback_multiCallback.js
mocha test/unit/testDownload.js
mocha test/unit/testDownload_2.js
mocha test/unit/testExecutionPlan.js
Expand Down
54 changes: 54 additions & 0 deletions test/unit/testCalledback_multiCallback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
'use strict';

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

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

describe('called back function ', function () {
it('can be called multiple times with new file path', function (done) {

var count = 0;
jf.filed( testPath )
.io(
function( obj, filePath) {
return testValue;
}
).calledback(
function(obj, filePath, callback){
setTimeout(
function(){
console.log("called back user process")
callback( new_testValue, testPath );
callback( new_testValue, testPath2 );
callback( new_testValue, testPath3 );
},
10);
}
).pass(
function(obj, filePath){
expect( path.resolve( testPath ) == filePath ||
path.resolve( testPath2 ) == filePath ||
path.resolve( testPath3 ) == filePath ).to.eql(true);
expect(obj).to.eql(new_testValue);

count ++;
if( count == 3 ) done();

}
).exec();

});

setTimeout(
function(){
},
20);

});

0 comments on commit d08a84a

Please sign in to comment.