Unit Test calles multiple times done

Hello, i have a problem with a unit test.
The node i develope sends msg in a loop like this:

for( let i = 0; i < array.lenght; i++){
      node.send([array[i], null, null,]);
}

Unit Test:

it('should get data (Array)', function (done) {
            const flow = getDefaultFlow();
            helper.load([CheckNode, serverNode], flow, function () {
                var nCheck = helper.getNode("Check");
                var nhelp = helper.getNode("Help");

                nCheck .receive({
                    payload: false
                });

                nhelp.on("input", function(msg) {
                    try {

                        msg.should.have.property('topic', "Data");
                        done();
                    } catch (err) {
                        console.log('err ' + err);
                        done(err);
                    }                
                });

                nCheck.receive({
                    payload: true
                });
            });
        });

My problem is that if i just send only one msg in the loop the test is working, but if i send multiple msg in the loop i get the error:
done() called multiple times

Can somebody tell me what i`m doing wrong?

Hi @TruFox

The handler for the input event is called for each message you send that node. Inside that handler you check the value of the topic property and then call done().

So yes, if you send multiple messages, you will end up calling done() multiple times.

A different approach is to push each message into an array within the input handler, and only once you have received the number you expect, loop through the array checking their contents and then call done at the end.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.