Skip to content

Commit

Permalink
doc: update examples in writing-tests.md
Browse files Browse the repository at this point in the history
`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]>
  • Loading branch information
GaryGSC authored and MylesBorins committed Dec 17, 2019
1 parent 56b3edc commit fd16e9f
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions doc/guides/writing-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,19 +162,22 @@ const assert = require('assert');
const http = require('http');

let request = 0;
let listening = 0;
let response = 0;
process.on('exit', function() {
process.on('exit', () => {
assert.equal(request, 1, 'http server "request" callback was not called');
assert.equal(listening, 1, 'http server "listening" callback was not called');
assert.equal(response, 1, 'http request "response" callback was not called');
});

const server = http.createServer((req, res) => {
request++;
res.end();
}).listen(0, function() {
}).listen(0, () => {
listening++;
const options = {
agent: null,
port: this.address().port
port: server.address().port
};
http.get(options, (res) => {
response++;
Expand All @@ -193,16 +196,16 @@ const http = require('http');

const server = http.createServer(common.mustCall((req, res) => {
res.end();
})).listen(0, function() {
})).listen(0, common.mustCall(() => {
const options = {
agent: null,
port: this.address().port
port: server.address().port
};
http.get(options, common.mustCall((res) => {
res.resume();
server.close();
}));
});
}));

```

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

const countdown = new Countdown(2, function() {
const countdown = new Countdown(2, () => {
console.log('.');
});

Expand Down

0 comments on commit fd16e9f

Please sign in to comment.