diff options
author | garygsc <garygsc@gmail.com> | 2019-10-25 17:04:26 -0600 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-11-05 23:21:02 +0100 |
commit | 074730081db3269fc3559598c0698a9f6b7b20c2 (patch) | |
tree | bbc89b648da5a790e7f3478bd3518757687802fb /doc/guides | |
parent | f04810531afba30c77163fe18f4d16c540d94eb9 (diff) | |
download | android-node-v8-074730081db3269fc3559598c0698a9f6b7b20c2.tar.gz android-node-v8-074730081db3269fc3559598c0698a9f6b7b20c2.tar.bz2 android-node-v8-074730081db3269fc3559598c0698a9f6b7b20c2.zip |
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: https://github.com/nodejs/node/pull/30126
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Diffstat (limited to 'doc/guides')
-rw-r--r-- | doc/guides/writing-tests.md | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/doc/guides/writing-tests.md b/doc/guides/writing-tests.md index 584b1d2373..7022bf8f93 100644 --- a/doc/guides/writing-tests.md +++ b/doc/guides/writing-tests.md @@ -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++; @@ -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(); })); -}); +})); ``` @@ -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('.'); }); |