Inclusive Tests
This feature is the inverse of .only()
.
By appending .skip()
, you may tell Mocha to ignore test case(s).
Anything skipped will be marked as pending, and reported as such.
Here’s an example of skipping an individual test:
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.
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.
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:
The above test will be reported as pending.
It’s also important to note that calling this.skip()
will effectively abort the test.
Contrast the above test with the following code:
Because this test does nothing, it will be reported as passing.
To skip multiple tests in this manner, use this.skip()
in a “before all” hook:
This will skip all it
, beforeEach/afterEach
, and describe
blocks within the suite.
before/after
hooks are skipped unless they are defined at the same level as the hook containing this.skip()
.
Before Mocha v3.0.0, this.skip()
was not supported in asynchronous tests and hooks.