Html 测试结果在QUnit中不可见,尽管它们正在运行

Html 测试结果在QUnit中不可见,尽管它们正在运行,html,css,qunit,Html,Css,Qunit,我有很多这样的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

我有很多这样的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>
这是一个不可见的:

<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>
  • 修饰web服务调用测试 (1) 5082毫秒

  • 可能是什么问题?

    我看到这一点的大部分时间是因为以下两个原因之一:

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

    (2) 一些源代码是异步的,因此可能会出现竞争条件

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

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

    我建议您缩小导致问题的测试范围,对测试块进行注释,并最终归结为一个有时通过有时暂停的测试。

    测试总是通过。我只是看不到结果。嗯。。。是的,我在你的问题中看到了这一点,但完全排除了这一点。:)很抱歉无论如何,我不确定为什么不应用该样式,但我猜仍然是一个异步问题(特别是对于require)。