6

I'm trying to skip tests if a condition returns true using this.skip() inside an "it", but I'm getting an error "this.skip is not a function". this is the simple code I'm trying to check it on:

var async = require('async');
var should = require('chai').should();
var chai = require('chai'),
should = chai.should();
expect = chai.expect;
chai.use(require('chai-sorted'));

describe('Testing skip...\n', function() {
        this.timeout(1000);
        it('test1', (done) => {
            this.skip();
            console.log("1")
            done();
        });

        it('test2', (done) => {         
            console.log("2");
            done();
        }); 

});

I installed "mocha@5.2.0 " since I saw it only works on since "mocha v3.0.0", but I still cant get it to work, and none of the past discussions on the subject seems to fix my problem.

Hris
  • 153
  • 13
rone
  • 83
  • 1
  • 7

1 Answers1

19

in order to use this in mocha, don't use arrow function. So, in your code you need to write it as

it('test1', function(done) { // use regular function here
  this.skip();
  console.log("1")
  done();
});

The best practice in Mocha is to discourage arrow function as described in https://mochajs.org/#arrow-functions

Hope it helps

deerawan
  • 8,002
  • 5
  • 42
  • 51