Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
szmarczak committed Feb 29, 2020
1 parent 47f4adf commit c0004bf
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions test/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

0 comments on commit c0004bf

Please # to comment.