From c0004bfbf5a04a5a32c3b7ff2fdd705007139585 Mon Sep 17 00:00:00 2001 From: Szymon Marczak <36894700+szmarczak@users.noreply.github.com> Date: Sat, 29 Feb 2020 21:06:50 +0100 Subject: [PATCH] test #994 --- test/hooks.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/hooks.ts b/test/hooks.ts index 838b29e6f..59577d12a 100644 --- a/test/hooks.ts +++ b/test/hooks.ts @@ -776,3 +776,25 @@ test('timeout can be modified using a hook', withServer, async (t, server, got) retry: 0 }), {message: 'Timeout awaiting \'request\' for 500ms'}); }); + +test('beforeRequest hook is called before each request', withServer, async (t, server, got) => { + server.post('/', echoUrl); + server.post('/redirect', redirectEndpoint); + + const buffer = Buffer.from('Hello, Got!'); + let counts = 0; + + await got.post('redirect', { + body: buffer, + hooks: { + beforeRequest: [ + options => { + counts++; + t.is(options.headers['content-length'], String(buffer.length)); + } + ] + } + }); + + t.is(counts, 2); +});