
- JasmineJS 教程
- JasmineJS - 首頁
- JasmineJS - 概述
- JasmineJS - 設定環境
- JasmineJS - 編寫正文和執行
- JasmineJS - BDD 體系結構
- JasmineJS - 測試基本模組
- JasmineJS - 匹配器
- JasmineJS - 跳過塊
- JasmineJS - 等值檢查
- JasmineJS - 布林值檢查
- JasmineJS - 順序檢查
- JasmineJS - 空值檢查
- JasmineJS - 不等值檢查
- JasmineJS - 非數字檢查
- JasmineJS - 異常檢查
- JasmineJS - beforeEach()
- JasmineJS - afterEach()
- JasmineJS - 間諜
- JasmineJS 實用資源
- JasmineJS - 快速指南
- JasmineJS - 實用資源
- JasmineJS - 討論
JasmineJS - 跳過塊
Jasmine 還允許開發人員跳過一個或多個測試用例。這些技術既可以應用於規範級別,也可以應用於套件級別。根據應用的級別,這個塊分別稱為跳過規範和跳過套件。
在以下示例中,我們將學習如何使用“x”字元跳過特定的規範或套件。
跳過規範
我們將使用“x”在it語句前面修改之前的示例。
describe('This custom matcher example ', function() { beforeEach(function() { // We should add custom matched in beforeEach() function. jasmine.addMatchers({ validateAge: function() { return { compare: function(actual,expected) { var result = {}; result.pass = (actual > = 13 && actual < = 19); result.message = 'sorry u are not a teen '; return result; } }; } }); }); it('Lets see whether u are teen or not', function() { var myAge = 14; expect(myAge).validateAge(); }); xit('Lets see whether u are teen or not ', function() { //Skipping this Spec var yourAge = 18; }); });
如果我們執行這段 JavaScript 程式碼,我們會在瀏覽器中收到以下輸出結果。Jasmine 自身會通知使用者,具體的it塊已被用 “xit” 暫時停用。

跳過套件
同樣地,我們可以停用 describe 塊,以便實現跳過套件技術。在以下示例中,我們將學習跳過套件塊的過程。
xdescribe('This custom matcher example ', function() { //Skipping the entire describe block beforeEach(function() { // We should add custom matched in beforeEach() function. jasmine.addMatchers({ validateAge: function() { return { compare: function(actual,expected) { var result = {}; result.pass = (actual >=13 && actual<=19); result.message ='sorry u are not a teen '; return result; } }; } }); }); it('Lets see whether u are teen or not', function() { var myAge = 14; expect(myAge).validateAge(); }); it('Lets see whether u are teen or not ', function() { var yourAge = 18; expect(yourAge).validateAge(); }); });
以上程式碼會生成以下螢幕截圖作為輸出。

正如我們在訊息欄中看到的那樣,它顯示了兩個處於待定狀態的規範塊,這意味著這兩個規範塊使用“x”字元被停用。在下一章中,我們將討論不同型別的 Jasmine 測試場景。
廣告