How can I unit test jquery dialog get displayed?
jquery, jquery-ui-dialog, qunit, sinon, unit-testing
Solution
You need to mock jQuery.fn like this:
var jQueryMock = sinon.mock(jQuery.fn);
Problem
I wrote below code, try to test if a jquery dialog get excused and displayed. ``` var jqueryMock = sinon.mock(jQuery); var dialogExpectation = jqueryMock.expects("dialog"); dialogExpectation.once(); //call my function, in which create a jquery dialog. equals(dialogExpectation.verify(), true, "Dialog is displayed"); jqueryMock.restore(); ``` However, it shows me the error: Died on test #1: Attempted to wrap undefined property dialog as function - { "message": "Attempted to wrap undefined property dialog as function", "name": "TypeError" } The jquery code is very simple: ``` displayMessage: function (message, title, hashId) { //some logic to build the message, title and hashId. $(messageDiv).dialog({ height: 240, width: 375, modal: true, title: title, resizable: false, buttons: [{ text: localizedErrorMessages['OkText'], click: function () { $(this).dialog("close"); } }] }); // end of dialog } // end of displayMessage ``` Anyone know how to mock the jquery dialog and write unit test in this scenario?