diff --git a/src/__TEST__/range.spec.ts b/src/__TEST__/range.spec.ts index 84ebcbd..62a7342 100644 --- a/src/__TEST__/range.spec.ts +++ b/src/__TEST__/range.spec.ts @@ -272,6 +272,47 @@ describe(`rangeFactory`, () => { }) }) + const { resolver: ExampleZeroStart } = rangeFactory({ + name: `ExampleRange`, + start: 0, + end: 1 + }) + + describe(`valid:allowsZero`, () => { + describe(`as int`, () => { + it(`serialize`, () => { + expect(ExampleZeroStart.serialize(0)).toBe(0) + }) + + it(`parseValue`, () => { + expect(ExampleZeroStart.parseValue(0)).toBe(0) + }) + + it(`parseLiteral`, () => { + expect( + // @ts-ignore + ExampleZeroStart.parseLiteral({ value: 0, kind: Kind.INT }, {}) + ).toBe(0) + }) + }) + + describe(`as string`, () => { + it(`serialize`, () => { + expect(ExampleZeroStart.serialize(`0`)).toBe(0) + }) + + it(`parseValue`, () => { + expect(ExampleZeroStart.parseValue(`0`)).toBe(0) + }) + + it(`parseLiteral`, () => { + expect( + ExampleZeroStart.parseLiteral({ value: `0`, kind: Kind.INT }, {}) + ).toBe(0) + }) + }) + }) + const { resolver: ExampleFloatRange } = rangeFactory({ name: `ExampleFloatRange`, start: 0.25, diff --git a/src/range.ts b/src/range.ts index fd8a7e3..7c0e97a 100644 --- a/src/range.ts +++ b/src/range.ts @@ -14,7 +14,7 @@ export const rangeFactory = ({ name, start, end, float = false }: Config) => { .typeError(`Value is not a number: ${value}`) .notOneOf([Infinity, -Infinity], `Value is not a finite number: ${value}`) .required(`Value is not a number: ${value}`) - .positive(`Value is not a positive number: ${value}`) + .min(0, `Value is not a positive number: ${value}`) .validateSync(value) if (!float) { yupNumber() diff --git a/src/url.ts b/src/url.ts index 12210f5..d664198 100644 --- a/src/url.ts +++ b/src/url.ts @@ -6,15 +6,11 @@ const validate = (value: string) => yupString() .strict(true) .typeError(`Value is not string: ${value}`) - .test(`uri`, `Value is not a valid URL: ${value}`, val => { - try { - const result = parse(val as string) - if (!result.scheme) return false - return true - } catch (err) { - return false - } - }) + .test( + `uri`, + `Value is not a valid URL: ${value}`, + val => !!parse(val as string).scheme + ) .validateSync(value) export const URLScalar = `scalar URL`