Search code examples
javascriptnode.jsjasminejasmine-node

Why is my jasmine unit test not waiting for 'done'?


I have the test in my node application...

it('will call done', function(done) {
            myObj.fn(function(){

                done();
           }
});

and the code....

myObj.fn = function(success){
   setTimeout(2000000000,success);
}

When I run the test I get this in the output...

-MacBook-Pro:torus-pqdata user$ npm test

> [email protected] test /Stuff/code bases/2015/torus-pqdata
> jasmine-node specs/

However as you can see the unit test just exits without failing but I need it to timeout (I am trying to simulate something hanging). How do I get it to timeout?


Solution

  • Swap the arguments in setTimeout:

    myObj.fn = function(success){
        setTimeout(success, 200000000);
    }
    

    Here's some reference from MDN: https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setTimeout