44 lines
1.0 KiB
TypeScript
44 lines
1.0 KiB
TypeScript
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`
|
|
);
|
|
}
|
|
} |