How to programmatically skip a test in mocha?

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

    As @danielstjules answered here there is a way to skip test. @author of this topic has copied answer from github.com mochajs discussion, but there is no info in what version of mocha it available.

    I'm using grunt-mocha-test module for integrating mocha test functionality in my project. Jumping to last (for now) version - 0.12.7 bring me mocha version 2.4.5 with implementation of this.skip().

    So, in my package.json

      "devDependencies": {
        "grunt-mocha-test": "^0.12.7",
        ...
    

    And then

    npm install
    

    And it make me happy with this hook:

    describe('Feature', function() {
    
        before(function () {
    
            if (!Config.isFeaturePresent) {
    
                console.log('Feature not configured for that env, skipping...');
                this.skip();
            }
        });
    ...
    
        it('should return correct response on AB', function (done) {
    
            if (!Config.isABPresent) {
    
               return this.skip();
            }
    
            ...
    

提交回复
热议问题