我正在使用QUnit测试我正在编写的jQuery plugin,并希望使用blanket来生成覆盖率信息。
我的测试如下所示:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>My Awesome Test Suite</title>
<!-- Load local jQuery. This can be overridden with a ?jquery=___ param. -->
<script src="../libs/jquery-loader.js"></script>
<!-- Load local QUnit. -->
<link rel="stylesheet" href="../libs/qunit/qunit.css" media="screen">
<script src="../libs/qunit/qunit.js"></script>
<!-- Code Coverage with Blanket -->
<script src="../node_modules/blanket/dist/qunit/blanket.min.js"></script>
<!-- Load local lib and tests. -->
<script src="../build/thingToTest.js" data-cover></script>
<script src="../build/test/thingToTest_test.js"></script>
<!-- Removing access to jQuery and $. But it'll still be available as _$, if
you REALLY want to mess around with jQuery in the console. REMEMBER WE
ARE TESTING A PLUGIN HERE, THIS HELPS ENSURE BEST PRACTICES. REALLY. -->
<script>window._$ = jQuery.noConflict(true);</script>
</head>
<body>
<div id="qunit">
<h1 id="qunit-header">QUnit Tests</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
</div>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture">
<div class="thingToTest-container">
</div>
</div>
</body>
</html>当我在浏览器中打开它时,我看到了enable coverage选项,但当我选中该选项时,我得到错误信息
TypeError: 'undefined' is not an object (evaluating '$.fn')
Source: file:///Users/dave/src/thingToTest/test/thingToTest.html?coverage=true:317如果我注释掉这行
<script>window._$ = jQuery.noConflict(true);</script>那么blanket就可以正常工作了。
在简单的情况下,这是可以接受的,但在更复杂的情况下,我确实希望在noConflict模式下加载jQuery,以确保测试的纯洁性。
有没有办法做到这一点?
发布于 2014-07-15 04:39:24
我也有同样的问题。我将data-cover添加到用于qUnit测试的超文本标记语言中的jQuery脚本标记中,它起作用了,我认为仪器需要看到它。
编辑
我还注意到qUnit的html中有这一行。
<!-- Removing access to jQuery and $. But it'll still be available as _$, if
you REALLY want to mess around with jQuery in the console. REMEMBER WE
ARE TESTING A PLUGIN HERE, THIS HELPS ENSURE BEST PRACTICES. REALLY. -->
<script>window._$ = jQuery.noConflict(true);</script>通过删除该块,它不再需要jQuery标签上的数据封面。
https://stackoverflow.com/questions/24156924
复制相似问题