cloudflare/cloudflare-typescript

Public

mirrored from https://github.com/cloudflare/cloudflare-typescriptAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
7609e84ab3db53e79aefce6a112e90cb2a2bbba0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

tests/stringifyQuery.test.ts

26lines · modeblame

2d51afdcstainless-app[bot]2 years ago1import { APIClient } from 'cloudflare/core';
2
3const { stringifyQuery } = APIClient.prototype as any;
4
5describe('APIClient.stringifyQuery', () => {
6for (const [input, expected] of [
7[{ a: '1', b: 2, c: true }, 'a=1&b=2&c=true'],
8[{ a: null, b: false, c: undefined }, 'a=&b=false'],
9[{ 'a/b': 1.28341 }, `${encodeURIComponent('a/b')}=1.28341`],
10[
11{ 'a/b': 'c/d', 'e=f': 'g&h' },
12`${encodeURIComponent('a/b')}=${encodeURIComponent('c/d')}&${encodeURIComponent(
13'e=f',
14)}=${encodeURIComponent('g&h')}`,
15],
16]) {
17it(`${JSON.stringify(input)} -> ${expected}`, () => {
18expect(stringifyQuery(input)).toEqual(expected);
19});
20}
21for (const value of [[], {}, new Date()]) {
22it(`${JSON.stringify(value)} -> <error>`, () => {
23expect(() => stringifyQuery({ value })).toThrow(`Cannot stringify type ${typeof value}`);
24});
25}
26});