JasmineJS Skipping
Jasmine 还允许开发人员跳过一个或多个测试用例。这些技术可以应用于
规范级别或
套件级别。根据应用程序的级别,此块可以分别称为
Skipping Spec 和
Skipping Suite。
在下面的示例中,我们将学习如何使用
"x" 字符跳过特定的
Spec 或
Suite。
跳过规范
我们将在
it 语句之前使用
"x" 修改前面的示例。
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 本身会使用
"xit" 通知用户特定的
it 块被
禁用。
跳过套房
同样,我们可以禁用描述块以实现
跳过套件的技术。在下面的例子中,我们将了解跳过套件块的过程。
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 测试场景。