javascript - jasmine node testin child process callback -


I have an async function that returns the callback with the status code and path if I succeed to test it I would like to use jasmine that I received that status code and was assigned to the path in all future trials. I am getting an undetermined value for my tests ...

  function make_valid (cb) {var vdt = child.spawn ('node', base, {cwd: ims_working_dir, stdio : ['Pip', 'pipe', 'pipe']}, function (error, stdout, stderr) {if (error! == null) {console.log ('spawn error:' + error);}}) ; Vdt.stdout.setEncoding ('UTF8'); Vdt.stdout.on ('data', function (data) {}); Vdt.on ('close', function (code) {if (code === 0) {cb (null, '/ home /');} else {cb (null, code);}}); Describe path = make_valid (cb)) ("IMS", function (CB) {var path}; jasmine.getEnv (). DefaultTimeoutInterval = 40000; first (function (done, CB) {console.log (from 'each first) ;) ();}); ("Path should not be nonsensical", function () {hope (path). Defined by TBI ();});});  

Here is the output:

  Failures: 1) The IMS path should not be empty Message: Expected to be defined undefined. Stacktrace: Error: Undefined to be expected to be defined. At zero; & Lt; Anonymous & gt; (/home/evang/Dev/dataanalytics/IMS_Tester/spec/ims-spec.js:46:16) Timer.listOnTimeout [timer.js: 110:15] as in [astimeout] 1 test ending in 0.014 seconds, 1 argument, 1 failure, 0 left  

If I want to write more tests on the path passed before me in every announcement, where I parse the file. I think I'm working wrongly with callback or maybe I need to use a detective I know!

You are setting the value of path with the return value Make_valid function, this function does not return any returns.

When I used the jasmine , call me (code this () for the tests only done () Function).

Before each test an asynchronous function is required, I used my run () and used () function.

Try some code like this (modified for your example):

  var code = null; First get (function () {// token} so that we can make test cases. Async use jasmine's async support run (function () (make_valid (function (error, returnCode) {if (error) code = " ERROR_CODE "; else code = returnCode;}}}; waitsFor (function () {return code! == null;}) run (function () {hope (code) .toBeDefined ();});}); After each (work () {code = null;});  

edit : Based on our comments, suggestions for asynchronous testing of a one time Given approach which is below the line Other tests apply to this sample will be -spec.js . External it () done () .

 Internal test will not be passed if not used by the  / * jslint node * true * / "strict use"; description ("full, external test", function () {var code = zero; Must be setup for testing ", function (done) {make_valid (function (error, return code) {expected (return code) .toBeDefined (); Code = returnCode; Done ();});}); Description ("internal test", function () (this ("internal test 1", function () {expected (code) .not.toBeNull ();}); ("internal test 2", function () {hope ( Code). TBE (200);});});}); Function Make _Willback (callback) {setTimeout (function () {callback (tap, 200);), 500); }  

Comments