@replrn/testing-utility
TypeScript icon, indicating that this package has built-in type declarations

0.0.0 • Public • Published

Testing Utility

Usage

nameOf

The nameOf function provides type-safe ways to get formatted names from functions, classes and their properties.

import { nameOf } from "@replrn/testing-utility";
import { expect } from "expect";

class MyClass {
    myProperty: string = "";
    myOtherProperty: number = 0;
}

const className = nameOf(MyClass);
expect(className).toBe("My Class");

const propertyName = nameOf(MyClass, "myProperty");
expect(propertyName).toBe("My Class: My Property");

const properties = nameOf(MyClass, ["myProperty", "myOtherProperty"]);
expect(properties).toBe("My Class: My Property | My Other Property");

const withDetail = nameOf(MyClass, "myProperty", "detail");
expect(withDetail).toBe("My Class: My Property (detail)");
import { nameOf } from "@replrn/testing-utility";
import { expect } from "expect";

function myFunction() { }

const functionName = nameOf(myFunction);
expect(functionName).toBe("My Function");

const withDetail = nameOf(myFunction, "detail");
expect(withDetail).toBe("My Function: Detail");

isDefined

The isDefined function is a type guard for Vitest's expect. It narrows the type of the expectation to exclude undefined/null.

import { expectIsDefined } from "@replrn/testing-utility";
import { expectTypeOf } from "expect-type";

let x: number | undefined;

expectTypeOf(x).toBeNullable();
expectTypeOf(x).not.toBeNumber();

expectIsDefined(x);

expectTypeOf(x).not.toBeNullable();
expectTypeOf(x).toBeNumber();

Readme

Keywords

none

Package Sidebar

Install

npm i @replrn/testing-utility

Weekly Downloads

1

Version

0.0.0

License

none

Unpacked Size

10.4 kB

Total Files

9

Last publish

Collaborators

  • p-buddy