UNPKG

oral-ts

Version:

a testing framework for typescript

42 lines 1.5 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Match = void 0; var chalk_1 = __importDefault(require("chalk")); function resolver(regex, found, key) { if (!found.match(regex)) { this.emit("fail", key, "Match"); console.log(chalk_1.default.green("given pattern :- " + regex + "\n") + chalk_1.default.red("doesnt match :- " + found)); } else { this.emit("pass", key, "Match"); } } function Match(regex) { return function (target, key, descriptor) { var original = descriptor.value; Reflect.defineMetadata("role", "assertion", target, key); descriptor.value = function () { var _this = this; var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } var found = original.apply(this, args); if (found !== undefined) { if (found.constructor.name === "Promise") { found.then(function (found) { return resolver.apply(_this, [regex, found, key]); }); } else resolver.apply(this, [regex, found, key]); } return found; }; return descriptor; }; } exports.Match = Match; //# sourceMappingURL=match.js.map