mercredi 3 juin 2015

how to unit test console output with mocha on nodejs

Take into account the following example javascript code below:

function privateFunction (time) {
  if (time < 12) { console.log('Good morning'); }
  if (time >= 12 && time <19) { console.log('Good afternoon'); }
  else { console.log('Good night!'); }
};

How should I unit test that on nodejs using mocha (and possibly sinonjs), noticing that this is a private function called inside a module? I need to pass in the argument and check if the function is logging the right thing to the console.

Can I do the same with console.warn and console.err?

Aucun commentaire:

Enregistrer un commentaire