formats.exposed/test/common/maybeJsonParse.test.ts

13 lines
406 B
TypeScript

import { assertEquals } from "assert";
import maybeJsonParse from "../../public/common/maybeJsonParse.js";
Deno.test("returns null if string can't be parsed", () => {
assertEquals(maybeJsonParse(""), null);
assertEquals(maybeJsonParse('{"hi":'), null);
});
Deno.test("parses valid JSON", () => {
assertEquals(maybeJsonParse("123"), 123);
assertEquals(maybeJsonParse('{"hi": 5}'), { hi: 5 });
});