-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a way of a programmatically skipping a test #1901
Comments
There does not appear a way to conditionally skip tests from the program itself, e.g. describe('foo', (d) => {
before(() => {
d.skip();
});
it('foo', (i) => {
i.skip();
});
}); |
Hm, have you tried: $ cat test.js
describe('foo', function() {
before(function() {
this.skip();
});
it('foo', function() {
// will not run
console.log('This will not be printed');
});
});
$ mocha test.js
foo
- foo
0 passing (9ms)
1 pending Async skip will hopefully land in the next minor release via #1618 |
In your example above: describe('foo', (d) => {
before(() => {
d.skip();
});
//...
}); d is undefined. Mocha doesn't pass anything to functions that wrap suites, only specs. |
Where is this documented? |
This is not documented as far as I can tell. I was looking to do the same thing and having trouble. The problem was an outdated version of Mocha. Updating to 2.3.3 allows me to do this: describe('skipping', function () {
it('should skip', function () {
var u = false;
this.skip();
expect(u).to.equal(true); // <= Will not throw because it's skipped
});
}); Of course, you can add conditional logic to skipping a test according to, say, environment variables. |
How about this? describe('something', function () {
(os === 'windows' ? it.skip : it)('should do something that doesnt work on windows', function () {
})
}) |
Skipping tests is broken right now in 2 ways. See fixes in #1945 (comment).
|
I think you telegraph the problem better if you tag the troublesome tests and use a mocha test filter in your build environment. In addition to tests failing in CI, it's not uncommon to have tests that fail only in Dev. note that I am not condoning this situation, only acknowledging that it exists. I think conditional logic conceals problems that should be surfaced, and loudly. Nonfunctioning tests are legitimate concerns, and burying them in the spec file means fewer eyeballs on the problem. All else being equal, I'd prefer my test library didn't make it easier for my coworkers to sneakily disable tests to make the build green. I deal with enough of that sort of thing without mocha.js being an Enabler to that dysfunction. |
Agreed that using Right now Mocha offers this feature, but it wasn't working well historically (unsure of the state in latest stable version of Mocha). It would be great that if there's a test suite feature, it at least worked. |
And I'm going to reiterate that I believe tests that don't work in Phantom should be tagged as such and any build that runs on phantom should filter those tests out. It is immediately clear from the build history that only part of the tests were run. This is IME no different than tagging tests as slow and running them in a separate build target or at the end of the test run. |
The problems with |
https://mochajs.org/#arrow-functions as docs says
|
– http://stackoverflow.com/q/32723167/368691
The text was updated successfully, but these errors were encountered: