@drozdik.m/unit-test
Version:
Unit test with test cases with Assert functions. Simple and easy.
74 lines (73 loc) • 2.15 kB
TypeScript
import { Assert } from "./Assert";
import { IResultJSON, ITestCaseResultJSON } from "./Interfaces/ResultJSON";
export { UnitTest, Assert, IResultJSON, ITestCaseResultJSON };
/**
* Unit test
*/
declare class UnitTest {
private testName;
private testCases;
private awaitingAsync;
private asyncCallbackFunction;
private checkInterval;
/**
* Create new unit test
* @param testName Test name
*/
constructor(testName: string);
/**
* Creates and saves new sync test case
* @param name Test case name
* @param testFunction Test case function
*/
AddTestCase(name: string, testFunction: SyncTestFunction): void;
/**
* Creates and saves new sync test case
* @param name Test case name
* @param testFunction Test case function
*/
AddSyncTestCase(name: string, testFunction: SyncTestFunction): void;
/**
* Creates and save new async test case
* @param name Test case name
* @param testFunction Test case function
*/
AddAsyncTestCase(name: string, testFunction: AsyncTestFunction): void;
/**
* Callback function for async test cases
* */
private AsyncTestCaseCallback;
/**
* Runs added test cases and logs result (sync and async)
* @param timeout Time to timeout [ms] (default is 60 sec)
*/
Run(timeout?: number): void;
/**
* Start counting timeout
* @param timeout
*/
StartTimeout(timeout: number): void;
/**
* Clear timeout
* */
ClearTimeout(): void;
/**
* Logs passed results JSON
* @param results IResultJSON
*/
static ShowResults(results: IResultJSON): void;
/**
* Returns results in JSON format
* @param callback If some async functions has been present, returns complete JSON here
*/
ResultsJSON(callback?: ResultCallbackJSON): IResultJSON;
}
interface ResultCallbackJSON {
(results: IResultJSON): any;
}
interface SyncTestFunction {
(): void;
}
interface AsyncTestFunction {
(Done: Function, Fail: Function): void;
}