-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.ts
38 lines (29 loc) · 1 KB
/
index.test.ts
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
import { test, expect } from "@jest/globals";
import { parse, parseJSONValue, parseJSONObject, parseJSONArray, parseString, isJSONArray } from "../source";
test("parse invalid", () => {
expect(parse('{"ok":true}', isJSONArray)).toBe(undefined);
});
test("parseJSONValue object", () => {
expect(parseJSONValue('{"ok":true}')).toEqual({ ok: true });
});
test("parseJSONValue array", () => {
expect(parseJSONValue('[{"ok":true}]')).toEqual([{ ok: true }]);
});
test("parseJSONValue string", () => {
expect(parseJSONValue('"ok"')).toBe("ok");
});
test("parseJSONValue undefined", () => {
expect(parseJSONValue(undefined)).toBe(undefined);
});
test("parseJSONValue invalid", () => {
expect(parseJSONValue("ok")).toBe(undefined);
});
test("parseJSONObject", () => {
expect(parseJSONObject('{"ok":true}')).toEqual({ ok: true });
});
test("parseJSONArray", () => {
expect(parseJSONArray('[{"ok":true}]')).toEqual([{ ok: true }]);
});
test("parseString", () => {
expect(parseString('"ok"')).toBe("ok");
});