UNPKG

@3fv/guard

Version:

TypeScript guard suite

28 lines 1.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); require("jest"); const index_js_1 = require("../index.js"); function throwErr() { throw new Error('err'); } test(`getValue`, () => { let errorHandled = false; (0, index_js_1.setGuardErrorHandler)(() => errorHandled = true); expect((0, index_js_1.getValue)(() => { throw new Error('err'); // noinspection UnreachableCodeJS return 0; }, 1)).toBe(1); expect(errorHandled).toBeTruthy(); expect((0, index_js_1.getValue)(throwErr)).toBeUndefined(); expect((0, index_js_1.getValue)(() => 123, 1)).toBe(123); expect((0, index_js_1.getValue)(() => true, false)).toBe(true); }); test('guard', () => { expect(throwErr).toThrow(); expect(() => (0, index_js_1.guard)(throwErr)).not.toThrow(); const liftedGuard = index_js_1.guard.lift(throwErr); expect(typeof liftedGuard).toBe("function"); expect(liftedGuard).not.toThrow(); }); //# sourceMappingURL=Tools.spec.js.map