Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用设置和拆卸模块进行多个异步Qunit测试_Javascript_Jquery_Qunit - Fatal编程技术网

Javascript 如何使用设置和拆卸模块进行多个异步Qunit测试

Javascript 如何使用设置和拆卸模块进行多个异步Qunit测试,javascript,jquery,qunit,Javascript,Jquery,Qunit,我正在努力用Qunit设置一些异步测试。老实说,我不知道发生了什么,因为我是测试新手。我查了一些类似的问题,但似乎都不适合我 (function(){ var textBox, textArea, fixture = document.getElementById('qunit-fixture'); QUnit.module( "module", { setup: function( assert ) { textBox = docum

我正在努力用Qunit设置一些异步测试。老实说,我不知道发生了什么,因为我是测试新手。我查了一些类似的问题,但似乎都不适合我

(function(){

  var textBox, textArea,
     fixture = document.getElementById('qunit-fixture');

  QUnit.module( "module", {

    setup: function( assert ) {

      textBox        = document.createElement('input');
      textBox.type   = 'text';
      textBox.value  = '';

      textArea       = document.createElement('textarea');
      textArea.value = ' ';

      textBox.setAttribute("id", "textBox");
      textArea.setAttribute("id", "textArea");

      fixture.appendChild(textBox);
      fixture.appendChild(textArea);

    },

    teardown: function( assert ) {

      fixture.removeChild(textBox);
      fixture.removeChild(textArea);

    }

  });

  QUnit.asyncTest( "test a", function( assert ) {

    expect(1);

    setTimeout(function() {
      textBox.value = 'a'
    }, 250);

    setTimeout(function() {
      assert.deepEqual(textBox.value, 'a');
      QUnit.start();
    }, 500);

  });

  QUnit.asyncTest( "test b", function( assert ) {

   expect(1);

    setTimeout(function() {
      textBox.value = 'b'
    }, 250);

    setTimeout(function() {
      assert.deepEqual(textBox.value, 'b');
      QUnit.start();
    }, 500);

  });

}());

当我在浏览器中运行时,它会显示:1。模块:测试b1,所以我猜这只是运行最后一个测试,或者第一个测试还没有完成,或者什么的?困惑,请帮忙。

嗯。。。我已经将您的代码复制到一个测试文件中并运行它,一切正常,我看到两个测试都通过了。也就是说,QUnit允许您重新运行单个测试。。。您能在浏览器中检查URL吗?它是否指示要运行的测试编号?控制台中是否有任何错误

此外,请注意,在该模块中的每次测试后,qunit fixture div都会自动重置,因此您不需要使用拆卸方法。相反,您可以简单地向HTML文件中的qunit fixture div添加输入和文本区域,然后让qunit为您重置它

我的test.html文件:

<!doctype html>
<html>
  <head>
    <link rel="stylesheet" href="vendor/qunit-1.14.0.css" />
  </head>
  <body>
    <div id="qunit"></div>
    <div id="qunit-fixture"></div>

    <script src="vendor/qunit-1.14.0.js"></script>
    <script>
      // your code here...
    </script>
  </body>
</html>

是的,我发现几天后当我回到这里时,它似乎起了作用。我知道为什么。谢谢你提供的关于夹具自动复位的信息,我会试试的。谢谢