UNPKG

@push.rocks/smartexpect

Version:

A testing library to manage expectations in code, offering both synchronous and asynchronous assertion methods.

44 lines (38 loc) 1.03 kB
import { Assertion } from '../smartexpect.classes.assertion.js'; import type { TExecutionType } from '../types.js'; /** * Namespace for type-based matchers */ export class TypeMatchers<M extends TExecutionType> { constructor(private assertion: Assertion<any, M>) {} toBeTypeofString() { return this.assertion.customAssertion( (v) => typeof v === 'string', `Expected type to be 'string'` ); } toBeTypeofNumber() { return this.assertion.customAssertion( (v) => typeof v === 'number', `Expected type to be 'number'` ); } toBeTypeofBoolean() { return this.assertion.customAssertion( (v) => typeof v === 'boolean', `Expected type to be 'boolean'` ); } toBeTypeOf(typeName: string) { return this.assertion.customAssertion( (v) => typeof v === typeName, `Expected type to be '${typeName}'` ); } toBeDefined() { return this.assertion.customAssertion( (v) => v !== undefined, `Expected value to be defined` ); } }