run prettier (#995)
This commit is contained in:
parent
968b951795
commit
1150b1d843
1 changed files with 32176 additions and 33684 deletions
|
|
@ -1,46 +1,46 @@
|
|||
import { z } from "zod";
|
||||
import { completable } from "./completable.js";
|
||||
import { z } from 'zod';
|
||||
import { completable } from './completable.js';
|
||||
|
||||
describe("completable", () => {
|
||||
it("preserves types and values of underlying schema", () => {
|
||||
const baseSchema = z.string();
|
||||
const schema = completable(baseSchema, () => []);
|
||||
describe('completable', () => {
|
||||
it('preserves types and values of underlying schema', () => {
|
||||
const baseSchema = z.string();
|
||||
const schema = completable(baseSchema, () => []);
|
||||
|
||||
expect(schema.parse("test")).toBe("test");
|
||||
expect(() => schema.parse(123)).toThrow();
|
||||
});
|
||||
expect(schema.parse('test')).toBe('test');
|
||||
expect(() => schema.parse(123)).toThrow();
|
||||
});
|
||||
|
||||
it("provides access to completion function", async () => {
|
||||
const completions = ["foo", "bar", "baz"];
|
||||
const schema = completable(z.string(), () => completions);
|
||||
it('provides access to completion function', async () => {
|
||||
const completions = ['foo', 'bar', 'baz'];
|
||||
const schema = completable(z.string(), () => completions);
|
||||
|
||||
expect(await schema._def.complete("")).toEqual(completions);
|
||||
});
|
||||
expect(await schema._def.complete('')).toEqual(completions);
|
||||
});
|
||||
|
||||
it("allows async completion functions", async () => {
|
||||
const completions = ["foo", "bar", "baz"];
|
||||
const schema = completable(z.string(), async () => completions);
|
||||
it('allows async completion functions', async () => {
|
||||
const completions = ['foo', 'bar', 'baz'];
|
||||
const schema = completable(z.string(), async () => completions);
|
||||
|
||||
expect(await schema._def.complete("")).toEqual(completions);
|
||||
});
|
||||
expect(await schema._def.complete('')).toEqual(completions);
|
||||
});
|
||||
|
||||
it("passes current value to completion function", async () => {
|
||||
const schema = completable(z.string(), (value) => [value + "!"]);
|
||||
it('passes current value to completion function', async () => {
|
||||
const schema = completable(z.string(), value => [value + '!']);
|
||||
|
||||
expect(await schema._def.complete("test")).toEqual(["test!"]);
|
||||
});
|
||||
expect(await schema._def.complete('test')).toEqual(['test!']);
|
||||
});
|
||||
|
||||
it("works with number schemas", async () => {
|
||||
const schema = completable(z.number(), () => [1, 2, 3]);
|
||||
it('works with number schemas', async () => {
|
||||
const schema = completable(z.number(), () => [1, 2, 3]);
|
||||
|
||||
expect(schema.parse(1)).toBe(1);
|
||||
expect(await schema._def.complete(0)).toEqual([1, 2, 3]);
|
||||
});
|
||||
expect(schema.parse(1)).toBe(1);
|
||||
expect(await schema._def.complete(0)).toEqual([1, 2, 3]);
|
||||
});
|
||||
|
||||
it("preserves schema description", () => {
|
||||
const desc = "test description";
|
||||
const schema = completable(z.string().describe(desc), () => []);
|
||||
it('preserves schema description', () => {
|
||||
const desc = 'test description';
|
||||
const schema = completable(z.string().describe(desc), () => []);
|
||||
|
||||
expect(schema.description).toBe(desc);
|
||||
});
|
||||
expect(schema.description).toBe(desc);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue