
- QUnit 教程
- QUnit - 主頁
- QUnit - 概覽
- QUnit - 環境設定
- QUnit - 基本用法
- QUnit - API
- QUnit - 使用斷言
- QUnit - 執行過程
- QUnit - 跳過測試
- QUnit - 僅測試
- QUnit - 非同步呼叫
- QUnit - 預期斷言
- QUnit - 回撥
- QUnit - 巢狀模組
- QUnit 有用的資源
- QUnit - 快速指南
- QUnit - 有用的資源
- QUnit - 討論
QUnit - 僅測試
有時我們的程式碼還沒有準備好,而用於測試該方法/程式碼的測試用例在執行時會失敗。QUnit.only 有助於解決這個問題。只使用 only 方法編寫的測試方法將被執行,而其他測試將不會執行。如果指定了多個 only 方法,則只會執行第一個方法。讓我們看看 only 方法的實際應用。
<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.only( "test case 2", function( assert ) { assert.ok( true, "Module A: in test case 2" ); }); QUnit.test( "test case 3", function( assert ) { assert.ok( true, "Module A: in test case 3" ); }); QUnit.test( "test case 4", function( assert ) { assert.ok( true, "Module A: in test case 4" ); }); </script> </body> </html>
驗證輸出
您應該看到以下結果 −
廣告