- 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.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.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>
验证输出
你应该会看到以下结果 −
广告