aboutsummaryrefslogtreecommitdiff
path: root/src/lib/Effect/json.test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/Effect/json.test.ts')
-rw-r--r--src/lib/Effect/json.test.ts19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/lib/Effect/json.test.ts b/src/lib/Effect/json.test.ts
index b315fe61..c13824fe 100644
--- a/src/lib/Effect/json.test.ts
+++ b/src/lib/Effect/json.test.ts
@@ -2,7 +2,9 @@ import { describe, expect, it } from "vitest";
import {
parseJsonStringOrDefault,
parseJsonStringOrThrow,
+ parseJsonStringWithSchemaOrDefault,
} from "$lib/Effect/json";
+import { Schema } from "effect";
describe("effect json parsing", () => {
it("parses valid json strings", () => {
@@ -21,4 +23,21 @@ describe("effect json parsing", () => {
ok: false,
});
});
+
+ it("decodes json with a schema and returns fallback on schema mismatch", () => {
+ expect(
+ parseJsonStringWithSchemaOrDefault(
+ "[1,2,3]",
+ Schema.Array(Schema.Number),
+ [],
+ ),
+ ).toEqual([1, 2, 3]);
+ expect(
+ parseJsonStringWithSchemaOrDefault(
+ `["a",2]`,
+ Schema.Array(Schema.Number),
+ [],
+ ),
+ ).toEqual([]);
+ });
});