Search code examples
jqueryjasminedocument-ready

How to unit test a document.ready() function using jasmine


How do you test document.ready block using Jasmine? To be more specific , if I have a block like this :

$(document).ready(
    function () {
        abc = true;
    }
});

How do you test that the inner function was called when the document was ready, using Jasmine?


Solution

  • How do you test document.ready block using Jasmine? To be more specific , > if I have a block like this :

    $(document).ready( function(){ abc= true; } );

    My understanding is that code you have written within $(document).ready closure above is not testable. This link has a good explanation of how to make it more testable : http://bittersweetryan.github.io/jasmine-presentation/#slide-17

    How do you test that the inner function was called when the document was ready, using Jasmine?

    Answered above by m59 in comment already.