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 "[email protected] " 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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With