QUnit – 仅测试
QUnit – 仅测试
有时会发生我们的代码未准备好并且编写用于测试该方法/代码的测试用例失败(如果运行)。QUnit.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>
验证输出
您应该会看到以下结果 –