predictype
Version:
PredicType is a library of pre-built and tested predicates for TypeScript, covering various data types and operations.
28 lines (27 loc) • 1.34 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const vitest_1 = require("vitest");
const promiseType_js_1 = require("./promiseType.js");
(0, vitest_1.describe)('promiseType', () => {
(0, vitest_1.it)('should return true for is_promise', () => {
const p = Promise.resolve(42);
(0, vitest_1.expect)((0, promiseType_js_1.promiseType)(p, 'is_promise')).toBe(true);
});
(0, vitest_1.it)('should return false for is_promise with non-promise', () => {
const n = 42;
(0, vitest_1.expect)((0, promiseType_js_1.promiseType)(n, 'is_promise')).toBe(false);
});
(0, vitest_1.it)('should return true for is_async_function', () => {
async function foo() { }
(0, vitest_1.expect)((0, promiseType_js_1.promiseType)(foo, 'is_async_function')).toBe(true);
});
(0, vitest_1.it)('should return false for is_async_function with non-async', () => {
function bar() { }
(0, vitest_1.expect)((0, promiseType_js_1.promiseType)(bar, 'is_async_function')).toBe(false);
});
(0, vitest_1.it)('should throw for unknown operation', () => {
const p = Promise.resolve(42);
// @ts-expect-error
(0, vitest_1.expect)(() => (0, promiseType_js_1.promiseType)(p, 'unknown')).toThrow('Unknown PromiseType operation');
});
});
;