forwardemail / forwardemail/supertest

Implementation for `tap` method for the promise chain

Open
#545 2 comments 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
14.4k
Forks
782
PR merge metrics
No merged PRs in 30d

Description

*This is an enhancement proposal.*

Sometimes I'm looking for a clean way to debugging the responses, so I'd like to propose (and implement) a `tap` method similar to the [Bluebird](http://bluebirdjs.com/docs/api/tap.html) method.

In short:

>Essentially like .then(), except that the value passed in is the value returned.
>
>This means you can insert .tap() into a .then() chain without affecting what is passed through the chain. (See example below).

A example could be:

```js
describe('GET /user', function() {
it('responds with json', function(done) {
request(app)
.get('/user')
.auth('username', 'password')
.set('Accept', 'application/json')
.tap(response => {
// do something with response object without affecting the chain.
console.log(response);
})
.expect('Content-Type', /json/)
.expect(200, done);
});
});
```

Or better:
```js
.tap(console.log)
```

I found this can be very useful. I'd like to hear your thoughts on this.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.