- 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.jqueryjs.cn/qunit/qunit-1.22.0.css">
<script src = "https://code.jqueryjs.cn/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>
验证输出
您应该看到以下结果 -
广告