feat(fetch): accept numeric and bool params (#9345)

This commit is contained in:
Yury Semikhatsky 2021-10-08 09:23:59 -07:00 committed by GitHub
parent 52f19a222e
commit 6c18f1a6f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 8 deletions

View file

@ -303,7 +303,7 @@ Emulates consistent window screen size available inside web page via `window.scr
Target URL.
## fetch-option-params
- `params` <[Object]<[string], [string]>>
- `params` <[Object]<[string], [string]|[float]|[boolean]>>
Query parameters to be send with the URL.

View file

@ -903,3 +903,29 @@ it('context request should export same storage state as context', async ({ conte
const pageState = await page.request.storageState();
expect(pageState).toEqual(contextState);
});
it('should accept bool and numeric params', async ({ context, page, server }) => {
let request;
const url = new URL(server.EMPTY_PAGE);
url.searchParams.set('str', 's');
url.searchParams.set('num', '10');
url.searchParams.set('bool', 'true');
url.searchParams.set('bool2', 'false');
server.setRoute(url.pathname + url.search, (req, res) => {
request = req;
server.serveFile(req, res);
});
await page.request.get(server.EMPTY_PAGE, {
params: {
'str': 's',
'num': 10,
'bool': true,
'bool2': false,
}
});
const params = new URLSearchParams(request.url.substr(request.url.indexOf('?')));
expect(params.get('str')).toEqual('s');
expect(params.get('num')).toEqual('10');
expect(params.get('bool')).toEqual('true');
expect(params.get('bool2')).toEqual('false');
});

14
types/types.d.ts vendored
View file

@ -11747,7 +11747,7 @@ export interface ApiRequestContext {
/**
* Query parameters to be send with the URL.
*/
params?: { [key: string]: string; };
params?: { [key: string]: string|number|boolean; };
/**
* Request timeout in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout.
@ -11835,7 +11835,7 @@ export interface ApiRequestContext {
/**
* Query parameters to be send with the URL.
*/
params?: { [key: string]: string; };
params?: { [key: string]: string|number|boolean; };
/**
* Request timeout in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout.
@ -11869,7 +11869,7 @@ export interface ApiRequestContext {
/**
* Query parameters to be send with the URL.
*/
params?: { [key: string]: string; };
params?: { [key: string]: string|number|boolean; };
/**
* Request timeout in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout.
@ -11903,7 +11903,7 @@ export interface ApiRequestContext {
/**
* Query parameters to be send with the URL.
*/
params?: { [key: string]: string; };
params?: { [key: string]: string|number|boolean; };
/**
* Request timeout in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout.
@ -11974,7 +11974,7 @@ export interface ApiRequestContext {
/**
* Query parameters to be send with the URL.
*/
params?: { [key: string]: string; };
params?: { [key: string]: string|number|boolean; };
/**
* Request timeout in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout.
@ -12045,7 +12045,7 @@ export interface ApiRequestContext {
/**
* Query parameters to be send with the URL.
*/
params?: { [key: string]: string; };
params?: { [key: string]: string|number|boolean; };
/**
* Request timeout in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout.
@ -12116,7 +12116,7 @@ export interface ApiRequestContext {
/**
* Query parameters to be send with the URL.
*/
params?: { [key: string]: string; };
params?: { [key: string]: string|number|boolean; };
/**
* Request timeout in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout.