open-index/open-npm huggingface dataset:
npm package: @replrn/testing-utility
Description: ## Usage
Latest version: 0.0.0

# Testing Utility

## Usage

### `nameOf`

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

```ts #nameOf-class
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)");
```

```ts #nameOf-function
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.

```ts #is-defined
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();
```