Skip to content

Commit b269ad0

Browse files
oliversalzburgcraigtaub
authored andcommitted
Clarify effect of .skip() (#3947)
The fact that code inside of a skipped suite is executed, is potentially counter-intuitive. By using alternative phrasing, we make it clear how mocha handles code in skipped suites. Closes #3932
1 parent 1e6cf3b commit b269ad0

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

docs/index.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -566,32 +566,36 @@ _Note_: Hooks, if present, will still be executed.
566566
567567
## Inclusive Tests
568568

569-
This feature is the inverse of `.only()`. By appending `.skip()`, you may tell Mocha to simply ignore these suite(s) and test case(s). Anything skipped will be marked as [pending](#pending-tests), and reported as such. Here's an example of skipping an entire suite:
569+
This feature is the inverse of `.only()`. By appending `.skip()`, you may tell Mocha to simply ignore test case(s). Anything skipped will be marked as [pending](#pending-tests), and reported as such. Here's an example of skipping an individual test:
570570

571571
```js
572572
describe('Array', function() {
573-
describe.skip('#indexOf()', function() {
574-
// ...
573+
describe('#indexOf()', function() {
574+
it.skip('should return -1 unless present', function() {
575+
// this test will not be run
576+
});
577+
578+
it('should return the index when present', function() {
579+
// this test will be run
580+
});
575581
});
576582
});
577583
```
578584

579-
Or a specific test-case:
585+
You can also put `.skip()` on an entire suite. This is equivalent to appending `.skip()` onto all tests in the suite. Hooks in the suite are also skipped.
580586

581587
```js
582588
describe('Array', function() {
583-
describe('#indexOf()', function() {
584-
it.skip('should return -1 unless present', function() {
589+
describe.skip('#indexOf()', function() {
590+
it('should return -1 unless present', function() {
585591
// this test will not be run
586592
});
587-
588-
it('should return the index when present', function() {
589-
// this test will be run
590-
});
591593
});
592594
});
593595
```
594596

597+
_Note_: Code in skipped suites, that is placed outside of hooks or tests is still executed, as mocha will still invoke the suite function to build up the suite structure for visualization.
598+
595599
> _Best practice_: Use `.skip()` instead of commenting tests out.
596600
597601
You may also skip _at runtime_ using `this.skip()`. If a test needs an environment or configuration which cannot be detected beforehand, a runtime skip is appropriate. For example:

0 commit comments

Comments
 (0)