gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 10:48:24 26 4
gpt4 key购买 nike

我开始深入研究 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com