cloudflare/cloudflare-typescript
Publicmirrored from https://github.com/cloudflare/cloudflare-typescriptAvailable
tests/stringifyQuery.test.ts
23lines · modeblame
8bab6894stainless-app[bot]1 years ago | 1 | // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
2d51afdcstainless-app[bot]2 years ago | 2 | |
8bab6894stainless-app[bot]1 years ago | 3 | import { Cloudflare } from 'cloudflare'; |
2d51afdcstainless-app[bot]2 years ago | 4 | |
8bab6894stainless-app[bot]1 years ago | 5 | const { stringifyQuery } = Cloudflare.prototype as any; |
| 6 | | |
8765005bstainless-app[bot]1 years ago | 7 | describe(stringifyQuery, () => { |
| 8 | for (const [input, expected] of [ | |
| 9 | [{ a: '1', b: 2, c: true }, 'a=1&b=2&c=true'], | |
| 10 | [{ a: null, b: false, c: undefined }, 'a=&b=false'], | |
| 11 | [{ 'a/b': 1.28341 }, `${encodeURIComponent('a/b')}=1.28341`], | |
| 12 | [ | |
| 13 | { 'a/b': 'c/d', 'e=f': 'g&h' }, | |
| 14 | `${encodeURIComponent('a/b')}=${encodeURIComponent('c/d')}&${encodeURIComponent( | |
| 15 | 'e=f', | |
| 16 | )}=${encodeURIComponent('g&h')}`, | |
| 17 | ], | |
| 18 | ]) { | |
| 19 | it(`${JSON.stringify(input)} -> ${expected}`, () => { | |
| 20 | expect(stringifyQuery(input)).toEqual(expected); | |
| 21 | }); | |
| 22 | } | |
| 23 | }); |