Skip to content

Commit

Permalink
Add type tests for literal()
Browse files Browse the repository at this point in the history
  • Loading branch information
jviide committed Jul 13, 2024
1 parent eb7e7b9 commit abdfc9c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion tests/literal.test.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
import { describe, it, expect } from "vitest";
import { describe, it, expect, expectTypeOf } from "vitest";
import * as v from "../src";

describe("literal()", () => {
it("accepts string literals", () => {
const t = v.literal("test");
expect(t.parse("test")).to.equal("test");
expectTypeOf<v.Infer<typeof t>>().toEqualTypeOf<"test">();
});
it("accepts number literals", () => {
const t = v.literal(1);
expect(t.parse(1)).to.equal(1);
expectTypeOf<v.Infer<typeof t>>().toEqualTypeOf<1>();
});
it("accepts bigint literals", () => {
const t = v.literal(1n);
expect(t.parse(1n)).to.equal(1n);
expectTypeOf<v.Infer<typeof t>>().toEqualTypeOf<1n>();
});
it("accepts boolean literals", () => {
const t = v.literal(true);
expect(t.parse(true)).to.equal(true);
expectTypeOf<v.Infer<typeof t>>().toEqualTypeOf<true>();
});
it("rejects other literals when expecting a string literal", () => {
const t = v.literal("test");
Expand Down

0 comments on commit abdfc9c

Please sign in to comment.