Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ec7ae05

Browse files
committed
add skip tutorial
1 parent 0be6f66 commit ec7ae05

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

src/tutorials.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ const moment = require('moment');
55
const axiosPath = require('./axiosPath');
66

77
const tutorials = [
8+
{
9+
title: 'Using `it.skip()` in Mocha',
10+
raw: './tutorials/mocha/it-skip.md',
11+
url: '/tutorials/mocha/it-skip',
12+
description: 'Here\'s how `it.skip()` works in Mocha',
13+
tags: ['mocha'],
14+
date: moment('2023-08-04')
15+
},
816
{
917
title: 'Working with Timezones using date-fns and date-fns-tz',
1018
raw: './tutorials/date-fns/tz.md',

tutorials/mocha/it-skip.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
The [`it.skip()` function](https://mochajs.org/#inclusive-tests) tells Mocha to skip that particular test.
2+
For example, in the following code, Mocha will **not** run `test2`.
3+
4+
```javascript
5+
it('test1', function() {});
6+
it.skip('test2', function() {});
7+
it('test3', function() {});
8+
```
9+
10+
Running Mocha on the above file will produce the following output.
11+
Because test2 was skipped, Mocha will indicate that there's 1 "pending" test - "pending" tests are another word for skipped tests.
12+
13+
```
14+
$ mocha ./test.js
15+
16+
17+
✓ test1
18+
- test2
19+
✓ test3
20+
21+
2 passing (4ms)
22+
1 pending
23+
24+
$
25+
```
26+
27+
We recommend using `skip()` instead of commenting out tests.
28+
The benefit of using `skip()` is that Mocha can tell you when there are tests skipped via the "pending" output, whereas Mocha can't tell you when there are commented out tests.
29+
30+
## With `describe()`
31+
32+
`.skip()` is the inverse of [`.only()`](./run-single-test): `skip()` skips the marked test, `only()` skips every test _other than_ the marked test.
33+
Like `only()`, you can use `skip()` with `describe()` to skip a whole block of tests as follows.
34+
35+
```javascript
36+
// Skip all tests in 'suite'
37+
describe.skip('suite', function() {
38+
it('test1', function() {});
39+
it('test2', function() {});
40+
});
41+
42+
it('test3', function() {});
43+
```
44+
45+
The above script produces the following output.
46+
47+
```
48+
$ mocha ./test.js
49+
50+
51+
✓ test3
52+
suite
53+
- test1
54+
- test2
55+
56+
57+
1 passing (3ms)
58+
2 pending
59+
60+
$
61+
```

0 commit comments

Comments
 (0)