javascript - 如何为 jQuery UI 对话框编写 qUnit 测试?

标签 javascript jquery jquery-ui jquery-ui-dialog qunit

我开始深入研究 qUnit,但我遇到了一个问题,我不确定如何正确编写测试。

该函数基本上是在按下按钮时提醒 jQuery UI 对话框。这是我的 qUnit 测试:

test( "If Text is Type, and Control is Textbox, Check Alert if Two Values are Present",  function() {

    //Add New Row
    $('.button').click();


    equal($('#jquery_ui_id').is(':visible'), true, "Prompt is Shown" );

});

问题是测试在 qUnit 中通过,但仅在重新加载时。所以当我第一次运行测试时它总是失败,然后在我重新加载时成功。

有谁知道这里发生了什么,或者以前遇到过这个问题?

最佳答案

通常,当您重新加载页面时 qUnit 测试在失败和成功之间切换时,这意味着您在测试后没有正确清理并且它们相互冲突。

如果您将元素添加到 DOM 并在模块中进行操作或不使用特殊的 #qunit-fixture 元素进行测试,您应该在该模块的末尾删除它们,以便下一个可以重新开始。

有关更多信息,请参阅有关 keeping qUnit tests atomic 的部分.

QUnit will reset the elements inside the #qunit-fixture element after each test, removing any events that may have existed. As long as you use elements only within this fixture, you don't have to manually clean up after your tests to keep them atomic.

关于javascript - 如何为 jQuery UI 对话框编写 qUnit 测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15003551/

相关文章:

javascript - 动态添加元素后更新指令

jquery - 我应该覆盖 jQuery UI 自定义样式表吗?

css - 如何防止 JQueryUI 上下文菜单出现在 IE9 中加载到 IFrame 中的 PDF 下方

javascript - Openlayer 2.x 集群

javascript - 如何编写多个条件的 if , else block ?

JavaScript 分配自变量

javascript - 在 contenteditable div 中为 div 启用调整大小

Javascript字母数字正则表达式不采用换行符

jquery - 带图标的动画底部三 Angular 形

jquery - 无法转换 JavaScript 参数 arg 0"nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS