- QUnit 教程
- QUnit - 主頁
- QUnit - 概述
- QUnit - 環境設定
- QUnit - 基本用法
- QUnit - API
- QUnit - 使用斷言
- QUnit - 執行過程
- QUnit - 跳過測試
- QUnit - 僅在測試
- QUnit - 非同步呼叫
- QUnit - 預期斷言
- QUnit - 回撥
- QUnit - 巢狀模組
- QUnit 有用資源
- QUnit - 快速指南
- QUnit - 有用資源
- QUnit - 討論
QUnit - 預期斷言
我們可以使用 assert.expect() 函式檢查測試中進行的斷言數。在以下示例中,我們期望在測試中進行三個斷言。
<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.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>
驗證輸出
您應該看到以下結果 -
廣告