如何为jQuery UI对话编写qUnit测试?(How to Write a qUnit test for a jQuery UI Dialog?)

编程入门 行业动态 更新时间:2024-10-16 08:18:53
何为jQuery UI对话编写qUnit测试?(How to Write a qUnit test for a jQuery UI Dialog?)

我开始深入研究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中传递, 但仅在重新加载时传递 因此,当我第一次运行测试时总会失败,然后在重新加载时成功。

有谁知道这里发生了什么,或者之前遇到过这种情况?

I'm starting to get deep into qUnit, but I ran into an issue I'm not sure how to properly write a test for.

The function basically alerts a jQuery UI dialog when a button is pushed. Here is my qUnit Test:

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" ); });

The issue is that the test passes in qUnit, but only on reload. So it always fails when I first run the test, then succeeds while I reload it.

Does anyone know what is going on here, or has ran into this before?

最满意答案

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

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

有关更多信息,请参阅有关保持qUnit测试原子的部分。

QUnit将在每次测试后重置#qunit-fixture元素内的元素,删除可能存在的任何事件。 只要您只在此灯具中使用元素,您就不必在测试后手动清理它们以使其保持原子状态。

Generally when a qUnit test toggles between failing and succeeding when you reload the page, it means you're not properly cleaning up after your tests and they are conflicting with each other.

If you add elements to the DOM and manipulate in a module or test without using the special #qunit-fixture element, you should be removing them at the end of that module so the next one can start fresh.

For more information, see the section on 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.

更多推荐

本文发布于:2023-07-17 13:06:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1144913.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:何为   测试   UI   qUnit   jQuery

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!