-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
71 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { describe, expect, it } from "bun:test"; | ||
import * as v from "valibot"; | ||
import * as z from "zod"; | ||
import { BunicornValidationError } from "../error/index.ts"; | ||
import { __validate } from "./validate.ts"; | ||
|
||
// Mock schema for Valibot | ||
const valibotSchema = v.string(); | ||
|
||
// Mock schema for Zod | ||
const zodSchema = z.string(); | ||
|
||
describe("__validate", () => { | ||
it("should validate using Valibot schema", () => { | ||
const input = "valid string"; | ||
const result = __validate(valibotSchema, input); | ||
expect(result).toBe(input); | ||
}); | ||
|
||
it("should throw BunicornValidationError for invalid Valibot input", () => { | ||
const input = 123; | ||
expect(() => __validate(valibotSchema, input)).toThrow( | ||
BunicornValidationError, | ||
); | ||
}); | ||
|
||
it("should validate using Zod schema", () => { | ||
const input = "valid string"; | ||
const result = __validate(zodSchema, input); | ||
expect(result).toBe(input); | ||
}); | ||
|
||
it("should throw BunicornValidationError for invalid Zod input", () => { | ||
const input = 123; | ||
expect(() => __validate(zodSchema, input)).toThrow(BunicornValidationError); | ||
}); | ||
|
||
it("should validate using raw schema", () => { | ||
const rawSchema = (input: unknown) => { | ||
if (typeof input !== "string") { | ||
throw new Error("Must be a string"); | ||
} | ||
return input; | ||
}; | ||
const input = "valid string"; | ||
const result = __validate(rawSchema, input); | ||
expect(result).toBe(input); | ||
}); | ||
|
||
it("should throw BunicornValidationError for invalid raw schema input", () => { | ||
const rawSchema = (input: unknown) => { | ||
if (typeof input !== "string") { | ||
throw new Error("Must be a string"); | ||
} | ||
return input; | ||
}; | ||
const input = 123; | ||
expect(() => __validate(rawSchema, input)).toThrow(BunicornValidationError); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters