cloudflare/cloudflare-typescript
Publicmirrored fromhttps://github.com/cloudflare/cloudflare-typescriptAvailable
tests/stringifyQuery.test.ts
23lines · modecode
| 1 | // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | |
| 3 | import { Cloudflare } from 'cloudflare'; |
| 4 | |
| 5 | const { stringifyQuery } = Cloudflare.prototype as any; |
| 6 | |
| 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 | }); |
| 24 | |