本文介绍了如何以编程方式跳过摩卡咖啡中的测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个代码,其中某些测试在CI环境中总是会失败.我想根据环境条件禁用它们.
I have a code where certain tests will always fail in CI environment. I would like to disable them based on an environment condition.
如何在运行时执行期间以编程方式跳过Mocha中的测试?
How to programmatically skip a test in mocha during the runtime execution?
推荐答案
有一种未记录的以编程方式跳过测试的方式:
There is an undocumented way of programmatically skipping tests:
// test.js
describe('foo', function() {
before(function() {
this.skip();
});
it('foo', function() {
// will not run
console.log('This will not be printed');
});
});
运行:
$ mocha test.js
foo
- foo
0 passing (9ms)
1 pending
这在 https://github.com/mochajs/mocha/issues/1901 .
This is discussed in https://github.com/mochajs/mocha/issues/1901.
这篇关于如何以编程方式跳过摩卡咖啡中的测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!