我开始深入研究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.
更多推荐
发布评论