UNPKG

@drozdik.m/unit-test

Version:

Unit test with test cases with Assert functions. Simple and easy.

76 lines (75 loc) 2.83 kB
var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); exports.__esModule = true; var TestCase_1 = require("./TestCase"); var AsyncTestCase = /** @class */ (function (_super) { __extends(AsyncTestCase, _super); //-------------------------------------------------- //----------CONSTRUCTOR----------------------------- //-------------------------------------------------- /** * Creates new instance of AsyncTestCase * @param name Name of the test case * @param useCaseFunction Function to run * @param callbackFunction Function called on test case done */ function AsyncTestCase(name, useCaseFunction, callbackFunction) { var _this = _super.call(this, name, useCaseFunction) || this; //-------------------------------------------------- //----------PROPERTIES------------------------------ //-------------------------------------------------- _this.callbackFunction = null; _this.isRunning = false; _this.callbackFunction = callbackFunction; _this.Done = _this.Done.bind(_this); _this.Fail = _this.Fail.bind(_this); return _this; } //-------------------------------------------------- //----------METHODS--------------------------------- //-------------------------------------------------- AsyncTestCase.prototype.Run = function () { try { this.useCaseFunction(this.Done, this.Fail); } catch (error) { this.error = error; this.success = false; } this.isRunning = true; }; /** * Success callback * */ AsyncTestCase.prototype.Done = function () { this.isDone = true; this.isRunning = false; this.success = true; this.callbackFunction(); }; /** * Fail callback * */ AsyncTestCase.prototype.Fail = function () { this.isDone = true; this.isRunning = false; this.success = false; this.callbackFunction(); }; AsyncTestCase.prototype.IsRunning = function () { return this.isRunning; }; return AsyncTestCase; }(TestCase_1.TestCase)); exports.AsyncTestCase = AsyncTestCase;