UNPKG

kizu

Version:

An easy-to-use, fast, and defensive Typescript/Javascript test runner designed to help you to write simple, readable, and maintainable tests.

42 lines 2.13 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.throws = throws; const isError_1 = require("./isError"); function throws(assertions, experiment, expectedErr, description) { return __awaiter(this, void 0, void 0, function* () { if (typeof experiment !== 'function') throw new Error('experiment must be a function'); if (!(expectedErr instanceof Error) && !(expectedErr instanceof RegExp)) throw new Error('expectedErr is not an instance of Error or a RegExp'); let actualErr; try { const result = experiment(); // Check if the result is a Promise if (result && typeof result.then === 'function') { // Handle async function - wait for the promise to resolve or reject yield result; // If we get here, the promise resolved without throwing throw new Error('experiment did not throw an error'); } // If we get here, the sync function completed without throwing throw new Error('experiment did not throw an error'); } catch (e) { actualErr = e; } if (!actualErr) { throw new Error('experiment did not throw an error'); } (0, isError_1.isError)(assertions, actualErr, expectedErr, description || 'throws()'); }); } //# sourceMappingURL=throws.js.map