在运行我的QUnit测试套件时(第一次)检查“Check for Globals”标志,测试变为红色,但是我引入了一个全局变量,如下所示:
window.jQuery110007089870080817491
该名称与$ .expando属性相同,似乎是某种唯一标识符。
我已经尝试调试测试,但是我无法找到何时将此属性添加到window对象。
我想知道是否有人知道这是什么,它用于什么,以及什么可以导致它被添加(并且不被删除)到窗口对象。
感谢
/尤
编辑:
当这种情况发生时我设法创建了一个最小的例子,看起来这是jquery-ui的一个问题。
<html>
<head>
<title>Unit Tests</title>
<link rel="stylesheet" href="css/lib/qunit/qunit-1.11.0.css" type="text/css" media="screen">
<script type="text/javascript" src="js/lib/qunit/qunit-1.11.0.js"></script>
<script type="text/javascript" src="js/lib/jquery/jquery-1.10.0.js"></script>
<script type="text/javascript" src="js/lib/jquery/jquery-ui-1.10.3.custom.js"></script>
<script>
$(function() {
test("Test spinner", function() {
$("#spinner").spinner();
ok(true);
})
});
</script>
<body>
<h1 id="qunit-header">QUnit Test Suite</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture">
<input id="spinner" />
</div>
</body>
</html>
当打开QUnit Check for Globals标志时,此(以及修改jquery-ui小部件的其他测试)将失败。我试着运行jquery-ui自己的测试套件,激活了这个标志,他们的测试也失败了。
如果有人为此做了解决方法,那就太棒了,否则我想在运行涉及jquery-ui的单元测试时,我将不得不忍受Check for Globals。
答案 0 :(得分:0)
在创建spinner()方法时,我发现了以下几行。
11063 // turning off autocomplete prevents the browser from remembering the
11064 // value when navigating through history, so we re-enable autocomplete
11065 // if the page is unloaded before the widget is destroyed. #7790
11066 this._on( this.window, {
11067 beforeunload: function() {
11068 this.element.removeAttr( "autocomplete" );
11069 }
11070 });
这会将事件侦听器绑定到引入全局变量的window对象。如果你希望你的QUnit测试通过检查全局标志,你必须调用
$.spinner("destroy");
或其他jquery-ui小部件上的等效项,可以使用“autocomplete”来清理窗口对象上的所有事件侦听器。