Skip to content

Commit 313ae89

Browse files
committed
Test internal modifications by cacheable-request
Fixes #1567
1 parent 77df9c3 commit 313ae89

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

test/cache.ts

+25
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import test from 'ava';
44
import * as pEvent from 'p-event';
55
import * as getStream from 'get-stream';
66
import {Handler} from 'express';
7+
import * as nock from 'nock';
78
import CacheableLookup from 'cacheable-lookup';
89
import * as delay from 'delay';
910
import got, {CacheError, Response} from '../source/index';
@@ -375,3 +376,27 @@ test('http-cache-semantics typings', t => {
375376

376377
t.is(instance.defaults.options.cacheOptions.shared, false);
377378
});
379+
380+
test('allows internal modifications', async t => {
381+
nock('http://example.com').get('/test').reply(401);
382+
nock('http://example.com').get('/test').reply(200, JSON.stringify({
383+
wat: ['123']
384+
}));
385+
386+
const client = got.extend({
387+
cache: new Map(),
388+
hooks: {
389+
afterResponse: [
390+
async (response, retryWithMergedOptions) => {
391+
if (response.statusCode === 401) {
392+
return retryWithMergedOptions({});
393+
}
394+
395+
return response;
396+
}
397+
]
398+
}
399+
});
400+
401+
await t.notThrowsAsync(client.get('http://example.com/test'));
402+
});

0 commit comments

Comments
 (0)