@@ -125,34 +125,6 @@ Any subtests that are still outstanding when their parent finishes |
125 | 125 | are cancelled and treated as failures. Any subtest failures cause the parent |
126 | 126 | test to fail. |
127 | 127 |
|
128 | | -## Skipping tests |
129 | | - |
130 | | -Individual tests can be skipped by passing the `skip` option to the test, or by |
131 | | -calling the test context's `skip()` method as shown in the |
132 | | -following example. |
133 | | - |
134 | | -```js |
135 | | -// The skip option is used, but no message is provided. |
136 | | -test('skip option', { skip: true }, (t) => { |
137 | | - // This code is never executed. |
138 | | -}); |
139 | | - |
140 | | -// The skip option is used, and a message is provided. |
141 | | -test('skip option with message', { skip: 'this is skipped' }, (t) => { |
142 | | - // This code is never executed. |
143 | | -}); |
144 | | - |
145 | | -test('skip() method', (t) => { |
146 | | - // Make sure to return here as well if the test contains additional logic. |
147 | | - t.skip(); |
148 | | -}); |
149 | | - |
150 | | -test('skip() method with message', (t) => { |
151 | | - // Make sure to return here as well if the test contains additional logic. |
152 | | - t.skip('this is skipped'); |
153 | | -}); |
154 | | -``` |
155 | | - |
156 | 128 | ## Rerunning failed tests |
157 | 129 |
|
158 | 130 | The test runner supports persisting the state of the run to a file, allowing |
@@ -193,6 +165,68 @@ When the `--test-rerun-failures` option is used, the test runner will only run t |
193 | 165 | node --test-rerun-failures /path/to/state/file |
194 | 166 | ``` |
195 | 167 |
|
| 168 | +## `describe()` and `it()` aliases |
| 169 | + |
| 170 | +Suites and tests can also be written using the `describe()` and `it()` |
| 171 | +functions. [`describe()`][] is an alias for [`suite()`][], and [`it()`][] is an |
| 172 | +alias for [`test()`][]. |
| 173 | + |
| 174 | +```js |
| 175 | +describe('A thing', () => { |
| 176 | + it('should work', () => { |
| 177 | + assert.strictEqual(1, 1); |
| 178 | + }); |
| 179 | + |
| 180 | + it('should be ok', () => { |
| 181 | + assert.strictEqual(2, 2); |
| 182 | + }); |
| 183 | + |
| 184 | + describe('a nested thing', () => { |
| 185 | + it('should work', () => { |
| 186 | + assert.strictEqual(3, 3); |
| 187 | + }); |
| 188 | + }); |
| 189 | +}); |
| 190 | +``` |
| 191 | + |
| 192 | +`describe()` and `it()` are imported from the `node:test` module. |
| 193 | + |
| 194 | +```mjs |
| 195 | +import { describe, it } from 'node:test'; |
| 196 | +``` |
| 197 | + |
| 198 | +```cjs |
| 199 | +const { describe, it } = require('node:test'); |
| 200 | +``` |
| 201 | + |
| 202 | +## Skipping tests |
| 203 | + |
| 204 | +Individual tests can be skipped by passing the `skip` option to the test, or by |
| 205 | +calling the test context's `skip()` method as shown in the |
| 206 | +following example. |
| 207 | + |
| 208 | +```js |
| 209 | +// The skip option is used, but no message is provided. |
| 210 | +test('skip option', { skip: true }, (t) => { |
| 211 | + // This code is never executed. |
| 212 | +}); |
| 213 | + |
| 214 | +// The skip option is used, and a message is provided. |
| 215 | +test('skip option with message', { skip: 'this is skipped' }, (t) => { |
| 216 | + // This code is never executed. |
| 217 | +}); |
| 218 | + |
| 219 | +test('skip() method', (t) => { |
| 220 | + // Make sure to return here as well if the test contains additional logic. |
| 221 | + t.skip(); |
| 222 | +}); |
| 223 | + |
| 224 | +test('skip() method with message', (t) => { |
| 225 | + // Make sure to return here as well if the test contains additional logic. |
| 226 | + t.skip('this is skipped'); |
| 227 | +}); |
| 228 | +``` |
| 229 | + |
196 | 230 | ## TODO tests |
197 | 231 |
|
198 | 232 | Individual tests can be marked as flaky or incomplete by passing the `todo` |
@@ -275,40 +309,6 @@ it.todo('should do the thing', { expectFailure: true }, () => { |
275 | 309 | }); |
276 | 310 | ``` |
277 | 311 |
|
278 | | -## `describe()` and `it()` aliases |
279 | | - |
280 | | -Suites and tests can also be written using the `describe()` and `it()` |
281 | | -functions. [`describe()`][] is an alias for [`suite()`][], and [`it()`][] is an |
282 | | -alias for [`test()`][]. |
283 | | - |
284 | | -```js |
285 | | -describe('A thing', () => { |
286 | | - it('should work', () => { |
287 | | - assert.strictEqual(1, 1); |
288 | | - }); |
289 | | - |
290 | | - it('should be ok', () => { |
291 | | - assert.strictEqual(2, 2); |
292 | | - }); |
293 | | - |
294 | | - describe('a nested thing', () => { |
295 | | - it('should work', () => { |
296 | | - assert.strictEqual(3, 3); |
297 | | - }); |
298 | | - }); |
299 | | -}); |
300 | | -``` |
301 | | - |
302 | | -`describe()` and `it()` are imported from the `node:test` module. |
303 | | - |
304 | | -```mjs |
305 | | -import { describe, it } from 'node:test'; |
306 | | -``` |
307 | | - |
308 | | -```cjs |
309 | | -const { describe, it } = require('node:test'); |
310 | | -``` |
311 | | - |
312 | 312 | ## `only` tests |
313 | 313 |
|
314 | 314 | If Node.js is started with the [`--test-only`][] command-line option, or test |
|