UNPKG

type-fns

Version:

A set of types, type checks, and type guards for simpler, safer, and easier to read code.

25 lines 1.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const isAPromise_1 = require("./isAPromise"); describe('isAPromise', () => { it('should return true for promises', () => { const descision = (0, isAPromise_1.isAPromise)(Promise.resolve('hello')); expect(descision).toEqual(true); }); it('should return false for not promises', () => { const descision = (0, isAPromise_1.isAPromise)('hello'); expect(descision).toEqual(false); }); it('should be usable to narrow the typescript type', () => { // imagine we didn't know whether soonerOrLater is a promise or a string const soonerOrLater = Promise.resolve('hello'); // we can use this check to narrow down the typescript type and do operations specific to each type if ((0, isAPromise_1.isAPromise)(soonerOrLater)) { void soonerOrLater.then(() => 'done'); } else { void soonerOrLater.toLowerCase(); } }); }); //# sourceMappingURL=isAPromise.test.js.map