In your test, done has to be called to avoid timing out. In mocha if your 
unit under test causes an unexpected error, then you call done with that 
error so mocha can tell you. Here is a revision that calls `done` with the 
error.

before("Description", function(done) {
  require('path').run(event.options, {}, function (err, results) {
    if (err) {
      return done(err); // <- call done and avoid double callback
    }
    return done();
  });
});

Also, it is better to use real errors.

module.exports.run = function(event, context, cb) {
  myclass.queryAsync(...)
 .then(function (results) {
   if (results.field === "test") {
     return cb(new Error("error"));
   } else {
     return cb(null, "success");
   }
 })
 .catch(function (err) {
   return cb(err)
 });
};



On Friday, December 18, 2015 at 9:02:26 AM UTC-8, AndDM wrote:
>
> Hi, thanks for your reply, i've edit my code in:
>
> module.exports.run = function(event, context, cb) {
>   myclass.queryAsync(...)
>  .then(function (results) {
>    if (results.field === "test") {
>      return cb("error");
>    } else {
>      return cb(null, "success");
>    }
>  })
>  .catch(function (err) {
>    return cb(err)
>  });
> };
> The error is te same.
> Best regards
>
>
> Il giorno giovedì 17 dicembre 2015 05:08:38 UTC+1, Ebrahim Pasbani ha 
> scritto:
>>
>> You shouldn't throw exception in a callback.
>> Instead throwing of that exception call 
>> cb(error)
>>
>>
>>
>> On Thursday, 17 December 2015 04:40:56 UTC+3:30, AndDM wrote:
>>>
>>> Hi, i've this code:
>>>
>>> module.exports.run = function(event, context, cb) {
>>>   myclass.queryAsync(...)
>>>   .then(function (results) {
>>>     if (results.field === "test") {
>>>       throw "error";
>>>     } else {
>>>       return cb(null, "success");
>>>     }
>>>   })
>>>   .catch(function (err) {
>>>     return cb(err)
>>>   });
>>> };
>>>
>>> for promise i'm using bluebirdjs and i've attached this code to a mocha 
>>> test. If function give back a success, the test passes without problems. If 
>>> the test has errors, the stdout give back: Unhandled rejection null, the 
>>> mocha test goes on and then stops with exceeded timeout limit.
>>>
>>> My mocha test:
>>>   before("Description", function(done) {
>>>     require('path').run(event.options, {}, function (err, results) {
>>>       if (err) {
>>>         throw err;
>>>       }
>>>       done();
>>>     });
>>>   });
>>>   
>>>
>>> Some suggestions about that?
>>> Thanks for your time.
>>> Best regards
>>>
>>

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/66183516-5056-4775-b7ff-b9261efc240d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to