UNPKG

succulent

Version:

Powerful and easy runtime type checking

22 lines 981 B
/// <reference types="jest" /> import { assertType } from "../_util"; import { check, is, $boolean, $number, $string, $Tuple } from "../index"; test("$tuple", () => { const strings = $Tuple($string, $string, $string); const various = $Tuple($string, $number, $boolean); expect(is(["hi", "hey"], strings)).toBe(false); expect(is(["hi", "hey", "hello"], strings)).toBe(true); expect(is(["hi", "hey", "hello", "howdy"], strings)).toBe(false); expect(is(["hi", "hey", "hello"], various)).toBe(false); expect(is(["hi", 0, false], strings)).toBe(false); expect(is(["hi", 0, false], various)).toBe(true); expect(() => check(["hi", "hi"], strings)).toThrowErrorMatchingSnapshot(); expect(() => check(["hi", "hi", "hi", "howdy"], strings)).toThrowErrorMatchingSnapshot(); function _(x) { if (is(x, strings)) assertType(x); if (is(x, various)) assertType(x); } }); //# sourceMappingURL=tuple.test.js.map