How to programmatically skip a test in mocha?

前端 未结 14 1141
失恋的感觉
失恋的感觉 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:35

    I use runtime skipping from Mocha for the same scenario as you're describing. It is the copy paste from the docs:

    it('should only test in the correct environment', function() {
      if (/* check test environment */) return this.skip();
    
      // make assertions
    });
    

    As you can see, it skips the test based on environment. My own condition is if(process.env.NODE_ENV === 'continuous-integration').

提交回复
热议问题