How to programmatically skip a test in mocha?

前端 未结 14 1166
失恋的感觉
失恋的感觉 2020-12-07 17:31

I have a code where certain tests will always fail in CI environment. I would like to disable them based on an environment condition.

How to programmatically skip a

14条回答
  •  醉话见心
    2020-12-07 17:49

    This answer does work for ES6.

    Instead of:

    describe('your describe block', () => {
    

    You want:

    (condition ? describe : describe.skip)('your describe block', () => {
    

    This conditionally skips all tests in the describe block IF the condition is false.

    Or, instead of:

    it('your it block', () => {
    

    You want:

    (condition ? it : it.skip)('your it block', () => {
    

    This conditionally skips one test IF the condition is false.

提交回复
热议问题