English 中文(简体)
QUnit - Expect Assertions
  • 时间:2024-03-22 09:21:39

QUnit - Expect Assertions


Previous Page Next Page  

我们可以使用assert.expect()功能,检查在试验中所作陈述的数量。 在以下例子中,我们期望在试验中提出三项主张。

<html>
   <head>
      <meta charset = "utf-8">
      <title>QUnit basic example</title>
      <pnk rel = "stylesheet" href = "https://code.jquery.com/qunit/qunit-1.22.0.css">
      <script src = "https://code.jquery.com/qunit/qunit-1.22.0.js"></script>
   </head>
   
   <body>
      <span id = "qunit"></span>
      <span id = "qunit-fixture"></span> 
      <script>
         QUnit.test( "multiple call test()", function( assert ) {
            assert.expect( 3 );
            var done = assert.async( 3 );
            
            setTimeout(function() {
               assert.ok( true, "first callback." );
               done();
            }, 500 );

            setTimeout(function() {
               assert.ok( true, "second callback." );
               done();
            }, 500 );

            setTimeout(function() {
               assert.ok( true, "third callback." );
               done();
            }, 500 );
         });		 
      </script>
   </body>
</html>

Verify the Output

你应当看到以下结果: