@johanmnto/testings
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

@johanmnto/testings

Get Started

Performing single-tests

There is two ways to perform tests, the first one is by using UnitTest. Using UnitTest allows you to perform one unique test. To do so, you need to provide 3 informations to this function. The first one is the name of your unit-test, the second one is the script to test and the third one is the expected result. Let see an example:

import { Testings } from "@johanmnto/testings";
Testings.Testers.UnitTest("Some-Test", () => 2 * 9, 18);

The expected result is:

Some-Test: 0.074ms  → result: 👌 Passed

Peforming multiple-tests

The second way to perform tests is by using GroupTest. This function allows you to run multiple tests at once, it can be used when you want to make a test configuration. If you use Typescript, you can use UnitParameters<ExpectedReturnType>[] to define your test units. Let see an example:

import { Testings } from "@johanmnto/testings";
import { UnitParameters } from "@johanmnto/testings/dist/testers.d.ts";
const units: UnitParameters<any>[] = [
  {
    name: "Some-Test-Expect-18",
    runner: () => 2 * 9,
    expect: 18
  },
  {
    name: "Some-Test-Expect-9",
    runner: () => 3 * 3,
    expect: 9
  }
];

Testings.Testers.GroupTest(units);

Advanced usage

Filtering tests in GroupTest

GroupTest features a functionnality that defines which test units to run. To do so, you just need to put an array with the name of the tests you want to run on the second parameter of GroupTest. Assuming that we take the test unit configuration of GetStarted.PerformingMultipleTests, it means that if we want to run only the second test unit, the last line would look like:

// all the code set before
Testings.Testers.GroupTest(units, ["Some-Test-Expect-9"]);

Outputting synchronous/asynchronous data with LogGroup

LogGroup is a tool used in this package to output a lot of data in the console. It's used to output those data and manages their asynchronousity, etc... To use LogGroup you just need to create a LogGroup instance and add synchronous data with add, asynchronous data with scope and show them in the console using show. There is an example:

import { Testings } from "@johanmnto/testings";

const logInstance = new Testings.Loggers.LogGroup("nameOfYourLogGroup");
logInstance.add("nameOfTheDataToAdd", 12).add("anotherNameForAnotherData", {a: true});
// there is no need for any async/await expression or Promise structure, `LogGroup` automatically
// handle them.
logInstance.scope("somePromise", fetch("https://www.johanmontorfano.com"))
// it is not important if the promise is not fulfilled, the `show` function will always wait for 
// every promise to be finished before performing any actions.
          .show();

Readme

Keywords

Package Sidebar

Install

npm i @johanmnto/testings

Weekly Downloads

5

Version

1.1.0

License

ISC

Unpacked Size

16 kB

Total Files

13

Last publish

Collaborators

  • johanmnto