Qunit-skip-test

提供:Dev Guides
移動先:案内検索

QUnit-テストをスキップ

コードの準備ができておらず、そのメソッド/コードをテストするために記述されたテストケースが実行されると失敗することがあります。 QUnit.skip はこの点で役立ちます。 Skipメソッドを使用して記述されたテストメソッドは実行されません。 動作中のSkipメソッドを見てみましょう。

<html>
   <head>
      <meta charset = "utf-8">
      <title>QUnit basic example</title>
      <link 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>
      <div id = "qunit"></div>
      <div id = "qunit-fixture"></div>
      <script>
         QUnit.module( "Module A", {
            beforeEach: function( assert ) {
               assert.ok( true, "before test case" );
            }, afterEach: function( assert ) {
               assert.ok( true, "after test case" );
            }
         });

         QUnit.test( "test case 1", function( assert ) {
            assert.ok( true, "Module A: in test case 1" );
         });

         QUnit.skip( "test case 2", function( assert ) {
            assert.ok( true, "Module A: in test case 2" );
         });

         QUnit.module( "Module B" );
         QUnit.test( "test case 1", function( assert ) {
            assert.ok( true, "Module B: in test case 1" );
         });

         QUnit.skip( "test case 2", function( assert ) {
            assert.ok( true, "Module B: in test case 2" );
         });
      </script>
   </body>
</html>

出力を確認する

次の結果が表示されます-