summaryrefslogtreecommitdiff
path: root/tests/unit_node/querystring_test.ts
blob: 09672df370efa8a938848aea5d95d8661d66d728 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { assertEquals } from "@std/assert";
import { parse, stringify } from "node:querystring";

Deno.test({
  name: "stringify",
  fn() {
    assertEquals(
      stringify({
        a: "hello",
        b: 5,
        c: true,
        d: ["foo", "bar"],
      }),
      "a=hello&b=5&c=true&d=foo&d=bar",
    );
  },
});

Deno.test({
  name: "parse",
  fn() {
    assertEquals(parse("a=hello&b=5&c=true&d=foo&d=bar"), {
      a: "hello",
      b: "5",
      c: "true",
      d: ["foo", "bar"],
    });
  },
});

// https://github.com/denoland/deno/issues/21734
Deno.test({
  name: "stringify options no encode",
  fn() {
    assertEquals(
      stringify(
        {
          a: "hello",
          b: 5,
          c: true,
          d: ["foo", "bar"],
        },
        "&",
        "=",
        {},
      ),
      "a=hello&b=5&c=true&d=foo&d=bar",
    );
  },
});