aboutsummaryrefslogtreecommitdiff
path: root/tests/format.test.ts
blob: ae5d40c7a3a0feff0e0eac976383dd7c0be3cd81 (plain) (blame)
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
/*** IMPORT ------------------------------------------- ***/

import { expect, test } from "vitest";

/*** UTILITY ------------------------------------------ ***/

import { format } from "../source/library/graphql/format.ts";

/*** TESTS -------------------------------------------- ***/

test("format pretty-prints a valid query", () => {
  const input = "query Foo{viewer{id name}}";
  const expected = "query Foo {\n  viewer {\n    id\n    name\n  }\n}";
  expect(format(input)).toEqual(expected);
});

test("format returns the input unchanged on parse failure", () => {
  const input = "query { ...";
  expect(format(input)).toEqual(input);
});

test("format returns empty string for empty input", () => {
  expect(format("")).toEqual("");
});