Skip to content

Commit 63f937d

Browse files
GaryGSCtargos
authored andcommitted
doc: update examples in writing-tests.md
`writing-tests.md` states to use arrow functions when appropriate. This updates the examples to do that. Further, this syncs the docs with what's found in [`test/parallel/test-http-agent-null.js`](https://github.com/nodejs/node/blob/master/test/parallel/test-http-agent-null.js) PR-URL: #30126 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]>
1 parent 5cbe7c2 commit 63f937d

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

doc/guides/writing-tests.md

+10-7
Original file line numberDiff line numberDiff line change
@@ -162,19 +162,22 @@ const assert = require('assert');
162162
const http = require('http');
163163

164164
let request = 0;
165+
let listening = 0;
165166
let response = 0;
166-
process.on('exit', function() {
167+
process.on('exit', () => {
167168
assert.equal(request, 1, 'http server "request" callback was not called');
169+
assert.equal(listening, 1, 'http server "listening" callback was not called');
168170
assert.equal(response, 1, 'http request "response" callback was not called');
169171
});
170172

171173
const server = http.createServer((req, res) => {
172174
request++;
173175
res.end();
174-
}).listen(0, function() {
176+
}).listen(0, () => {
177+
listening++;
175178
const options = {
176179
agent: null,
177-
port: this.address().port
180+
port: server.address().port
178181
};
179182
http.get(options, (res) => {
180183
response++;
@@ -193,16 +196,16 @@ const http = require('http');
193196

194197
const server = http.createServer(common.mustCall((req, res) => {
195198
res.end();
196-
})).listen(0, function() {
199+
})).listen(0, common.mustCall(() => {
197200
const options = {
198201
agent: null,
199-
port: this.address().port
202+
port: server.address().port
200203
};
201204
http.get(options, common.mustCall((res) => {
202205
res.resume();
203206
server.close();
204207
}));
205-
});
208+
}));
206209

207210
```
208211

@@ -216,7 +219,7 @@ shutting down an HTTP server after a specific number of requests).
216219
```javascript
217220
const Countdown = require('../common/countdown');
218221

219-
const countdown = new Countdown(2, function() {
222+
const countdown = new Countdown(2, () => {
220223
console.log('.');
221224
});
222225

0 commit comments

Comments
 (0)