Skip to content

Commit 5059c1b

Browse files
fixup: add links to node docs & improve formatting
1 parent 016f38b commit 5059c1b

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

apps/site/pages/en/learn/test-runner/mocking.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ In the above, the first and second cases (the `it`s) can sabotage each other bec
141141

142142
### Modules + units
143143

144+
This leverages [`mock`](https://nodejs.org/api/test.html#class-mocktracker) from node's test runner.
145+
144146
```mjs
145147
import assert from 'node:assert/strict';
146148
import { before, describe, it, mock } from 'node:test';
@@ -178,9 +180,9 @@ describe('foo', { concurrency: true }, () => {
178180
});
179181
```
180182

181-
### Services
183+
### APIs
182184

183-
A little-known fact: node has a builtin way to mock `fetch`. [`undici`](https://github.com/nodejs/undici) is the Node.js implementation of fetch. You do not have to install it—it's shipped with node by default.
185+
A little-known fact: node has a builtin way to mock `fetch`. [`undici`](https://github.com/nodejs/undici) is the Node.js implementation of `fetch`. You do not have to install it—it's shipped with `node` by default.
184186

185187
```mjs displayName="endpoints.spec.mjs"
186188
import assert from 'node:assert/strict';
@@ -244,7 +246,9 @@ describe('endpoints', { concurrency: true }, () => {
244246

245247
### Time
246248

247-
Like Doctor Strange, you too can control time. You would usually do this just for convience to avoid artificially protracted test runs (do you really want to wait 3 minutes for that setTimeout to trigger?). You may also want to travel through time.
249+
Like Doctor Strange, you too can control time. You would usually do this just for convience to avoid artificially protracted test runs (do you really want to wait 3 minutes for that setTimeout to trigger?). You may also want to travel through time. This leverages [`mock timers`](https://nodejs.org/api/test.html#class-mocktimers) from node's test runner.
250+
251+
Note the use of time-zone here (`Z` in the time-stamps). Neglecting to include a consistent time-zone can (read: likely will) lead to unexpected restults.
248252

249253
```mjs displayName="master-time.spec.mjs"
250254
import assert from 'node:assert/strict';

0 commit comments

Comments
 (0)