小编use*_*671的帖子

如何显示单元测试jquery对话框?

我写下面的代码,尝试测试jquery对话框是否可以原谅和显示.

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();   
Run Code Online (Sandbox Code Playgroud)

但是,它向我显示错误:死于测试#1:尝试将未定义的属性对话框包装为函数 - {"message":"尝试将未定义的属性对话框包装为函数","name":"TypeError"}

jquery代码非常简单:

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
Run Code Online (Sandbox Code Playgroud)

在这种情况下,任何人都知道如何模拟jquery对话框并编写单元测试?

jquery unit-testing qunit jquery-ui-dialog sinon

5
推荐指数
1
解决办法
1171
查看次数

标签 统计

jquery ×1

jquery-ui-dialog ×1

qunit ×1

sinon ×1

unit-testing ×1