import { t, typeAsserts } from '../../index'; describe('arrayBuffer', () => { it('valid value', () => { expect.hasAssertions(); const buffer = new ArrayBuffer(10); const schema = t.arraybuffer(); expect(schema.validate(buffer)).toBe(true); expect(() => { typeAsserts(schema, buffer); }).not.toThrow(); expect(schema.validate(123)).toBe(false); expect(() => { typeAsserts(schema, 123); }).toThrow('param should be arraybuffer, but got 123'); expect(schema.validate('str')).toBe(false); expect(() => { typeAsserts(schema, 'str'); }).toThrow('param should be arraybuffer, but got "str"'); expect(schema.validate(true)).toBe(false); expect(() => { typeAsserts(schema, true); }).toThrow('param should be arraybuffer, but got true'); expect(schema.validate({})).toBe(false); expect(() => { typeAsserts(schema, {}); }).toThrow('param should be arraybuffer, but got a(n) object'); expect(schema.validate([])).toBe(false); expect(() => { typeAsserts(schema, []); }).toThrow('param should be arraybuffer, but got a(n) array'); }); it('optional optional', () => { expect.hasAssertions(); const schema = t.arraybuffer().optional(); expect(schema.validate(undefined)).toBe(true); expect(() => { typeAsserts(schema, undefined); }).not.toThrow(); }); });