[got] Improve beforRequest hook test

Move test case for beforeRequest hook to tests for other hooks.

Refs #31769
This commit is contained in:
ikokostya
2019-01-08 23:49:39 +03:00
parent a66df381a0
commit cd98b442e1
+14 -1
View File
@@ -268,7 +268,6 @@ got('http://todomvc.com', { cookieJar: new tough.CookieJar() });
got('http://todomvc.com', { retry: 2 });
got('http://todomvc.com', { retry: { retries: 2, methods: ['GET'], statusCodes: [408, 504], maxRetryAfter: 1 } });
got('http://todomvc.com', { throwHttpErrors: false });
got('http://todomvc.com', { hooks: { beforeRequest: [ () => 'foo']} });
// Test timeout options.
got('http://todomvc.com', {timeout: 1});
@@ -288,6 +287,15 @@ got('http://todomvc.com', {
got('http://todomvc.com', {timeout: 1}).catch((err) => err instanceof got.TimeoutError);
// Test hooks.
got('example.com', {
hooks: {
beforeRequest: [
options => {
options.headers!['x-foo'] = 'bar';
}
]
}
});
got('example.com', {
hooks: {
beforeRedirect: [
@@ -339,6 +347,11 @@ got('example.com', {
got('example.com', {
hooks: {
beforeRequest: [
async () => {
await doSomethingAsync();
}
],
beforeRedirect: [
async () => {
await doSomethingAsync();