尽管测试结果在运行,但在QUnit中不可见

亚当·阿罗德(Adam Arold)

我有很多这样的QUnit测试:

test('some test.', function() {
    equal(1, 1, "dummy");
});

我还有一个包含测试套件的.html文件:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Cache-Control" content="no-store" />
<title>QUnit Test Suite</title>
<link rel="stylesheet"
    href="http://code.jquery.com/qunit/qunit-1.16.0.css" type="text/css"
    media="screen">
    <script data-main="MainTest" src="lib/require.js"></script>
</head>
<body>  
    <div id="qunit"></div>
    <div id="dialog"></div>     
    <div id="test-content"></div>
</body>
</html>

我的问题是,当我打开此.html文件(testsuite.qunit.html)时,有时我看不到任何结果,而只是一个空白页。有时我看到一些结果。所有测试都在运行,我可以在顶部看到它:

测试在64毫秒内完成。161个声明(共161个)通过,0个失败。

我检查了qunit生成的html,看来QUnit无法将passcss类添加到某些测试中。这是一个可见的:

<li id="qunit-test-output-ca229798" class="pass">
<strong><span class="test-name">decorated web service call test</span>
<b class="counts">(1)</b></strong>
<a href="test.js">Rerun</a><span class="runtime">5082 ms</span>
<ol class="qunit-assert-list qunit-collapsed"></ol></li>

这是不可见的:

<li id="qunit-test-output-ca229798">
<strong><span class="test-name">decorated web service call test</span>
<b class="counts">(1)</b></strong>
<a href="test2.js">Rerun</a><span class="runtime">5082 ms</span>
<ol class="qunit-assert-list qunit-collapsed"></ol></li>

可能是什么问题呢?

乔丹·卡斯珀

在大多数情况下,我看到这是由于以下两个原因之一:

(1)源代码中的错误(这似乎不太可能,因为有时测试对您来说可以顺利通过),或

(2)一些源代码是异步的,因此可能会导致争用条件。

如果您有任何异步代码(ajax调用,setTimeout,setInterval等),则需要使用QUnit异步控制机制:

QUnit.test('a test with async code', function(assert) {
    var done = assert.async();  // tell QUnit you plan to do async stuff

    callSomeAsyncFunction(function() {
        // this is the callback for the async action

        // all of your assertions here

        done(); // tell QUnit you're done with async actions
    });
});

我建议您通过注释掉一些测试块来缩小范围,以缩小导致问题的测试范围,并最终解决单个测试有时会通过有时停滞的问题。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Admob标语在预览模式下可见,但在运行时不可见

UFT 结果在 Jenkins 报告中不可见

Href在scrapy结果中不可见,但在html中可见

HttpClient重定向结果在浏览器中不可见

导出的包在运行时不可见

UWP图像资产在运行时不可见

Android:TabHost在运行时不可见

Cron服务正在运行,但“顶部”不可见

ImageView存在,但在显示中不可见

xcode 崩溃上传成功但在 crashlytics 中不可见

发布了android应用,但在Google Play中不可见

OnClick事件触发但在.aspx中不可见

运行单元测试右键单击上下文项在IntelliJ 12中不可见

运行测试时服务弹性搜索不可见

MySQL 数据在 Toad Edge 中可见,但在 CLI 中不可见

Joomla模块在文章中可见,但在类别中不可见

为什么图像在Firefox中可见但在Chrome中不可见?

视图在设备中不可见,但在XML中可见

前景在真实设备中不可见,但在模拟器中可见

字符在vi中可见,但在cat中不可见。

文本选择在alert()中可见,但在html()中不可见

为什么Bootstrap轮播字幕在开发中可见但在生产中不可见?

使控件在 JavaScript 中可见,但在网页上不可见

为什么提交在 github 上可见,但在本地代表中不可见?

编辑文字提示在android studio设计预览中不可见,但在应用程序运行时在模拟器上可见

在运行时在android 6.0中请求权限时,应用程序名称不可见

图片在搜索结果中不可见

reCAPTCHA在Firefox中不可见-运行AdBlock和ghostery。

CSS 显示属性已设置但在代码运行时不可见