
- QUnit 教程
- QUnit - 首頁
- QUnit - 概覽
- QUnit - 環境設定
- QUnit - 基本用法
- QUnit - API
- QUnit - 使用斷言
- QUnit - 執行過程
- QUnit - 跳過測試
- QUnit - Only Test
- QUnit - 非同步呼叫
- QUnit - Expect 斷言
- QUnit - 回撥
- QUnit - 巢狀模組
- QUnit 實用資源
- QUnit - 快速指南
- QUnit - 實用資源
- QUnit - 討論
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>
驗證輸出
你應該會看到以下結果 −
廣告