D
D
Dmitry Spiridonov2015-03-27 19:39:20
Node.js
Dmitry Spiridonov, 2015-03-27 19:39:20

How to properly test such constructs using Mocha, Chai, Sinon?

Hello dear community. I ask you to suggest/indicate/direct to the true path). Just started learning nodejs and trying to start writing tests. And almost immediately the question arose:
There is, let's say, such a design, simplified:

method1(arg1, arg2, callback);

method2(arg3, arg4, callback);

method3(arg5, callback) {
  async.waterfall([
    function(cb) {
      method1(agr1, arg2, function(error, result1) {
        if (error) return cb(error);
        
        // ... smth code
        
        cb(null, result1);
      });
    },
    function(result1, cb) {
      method2(agr3, arg4, function(error, result2) {
        if (error) return cb(error);
        
        // ... smth code
        
        cb(null, result2);
      });
    }
  ], function(error, results) {
    
    // ... smth code
    
  });
});

The questions are, in fact, the following:
1) Is it worth testing method1, method2 separately? Or is it possible to test them already for a specific method3?
2) I read that sinon is used for a more concise type of tests, but even here the question arises, because it is not clear what to grab onto?
If I understand the general approach of writing tests correctly, it is desirable to wrap each method/function in a separate test. If some third-party things are used in one method, then wrap them in spy, stub, mock. But after a considerable amount of time, I still can’t find anything worthwhile specifically for this example.
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Kitmanov, 2015-03-27
@k12th

If you do not call method1 and method2 from outside, then you should not cover them with tests, because even if they disappear, the external code will not know about it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question