/* eslint-disable no-empty-function */ import { t, typeAsserts } from '../../index'; describe('function', () => { it('function', () => { expect.hasAssertions(); const schema = t.function(); expect(schema.validate(() => {})).toBe(true); expect(() => typeAsserts(schema, () => {})).not.toThrow(); expect(schema.validate(-1)).toBe(false); expect(() => typeAsserts(schema, -1)).toThrow(`param should be function, but got -1`); expect(schema.validate(+0)).toBe(false); expect(() => typeAsserts(schema, +0)).toThrow(`param should be function, but got 0`); expect(schema.validate(-0)).toBe(false); expect(() => typeAsserts(schema, -0)).toThrow(`param should be function, but got 0`); expect(schema.validate(1)).toBe(false); expect(() => typeAsserts(schema, 1)).toThrow(`param should be function, but got 1`); expect(schema.validate(NaN)).toBe(false); expect(() => typeAsserts(schema, NaN)).toThrow(`param should be function, but got NaN`); expect(schema.validate('str')).toBe(false); expect(() => typeAsserts(schema, 'str')).toThrow(`param should be function, but got "str"`); expect(schema.validate(Symbol(1))).toBe(false); expect(() => typeAsserts(schema, Symbol(1))).toThrow(`param should be function, but got a(n) symbol`); expect(schema.validate(null)).toBe(false); expect(() => typeAsserts(schema, null)).toThrow(`param should be function, but got null`); expect(schema.validate(undefined)).toBe(false); expect(() => typeAsserts(schema, undefined)).toThrow(`param should be function, but got undefined`); expect(schema.validate({})).toBe(false); expect(() => typeAsserts(schema, {})).toThrow(`param should be function, but got a(n) object`); expect(schema.validate(BigInt(1))).toBe(false); expect(() => typeAsserts(schema, BigInt(1))).toThrow(`param should be function, but got a(n) bigint`); }); it('optional', () => { expect.hasAssertions(); const schema = t.function().optional(); expect(schema.validate(undefined)).toBe(true); expect(() => { typeAsserts(schema, undefined); }).not.toThrow(); }); });