UNPKG

rc-js-util

Version:

A collection of TS and C++ utilities to help writing performant and correct applications, achieved through strict typing and (removable) invariant checking.

40 lines (33 loc) 826 B
import { _Production } from "./_production.js"; import { Test_setDefaultFlags } from "../test-util/test_set-default-flags.js"; describe("=> _Production.error", () => { beforeEach(() => { Test_setDefaultFlags(); }); describe("=> compilation checks", () => { it("| narrows types where used as a guard", () => { let r = foo(); if (typeof r === "string") { throw _Production.createError("test"); } ++r; return r; }); }); it("| throws an error with the expected message", () => { expect(() => { throw _Production.createError("test message"); }).toThrowError("test message"); }); }); function foo(): string | number { return 1; }