2025-04-28 19:10:27 +00:00
|
|
|
import { Assertion } from '../smartexpect.classes.assertion.js';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Namespace for type-based matchers
|
|
|
|
*/
|
|
|
|
export class TypeMatchers {
|
|
|
|
constructor(private assertion: Assertion<any>) {}
|
|
|
|
|
|
|
|
toBeTypeofString() {
|
2025-04-28 19:58:32 +00:00
|
|
|
return this.assertion.customAssertion(
|
|
|
|
(v) => typeof v === 'string',
|
|
|
|
`Expected type to be 'string'`
|
|
|
|
);
|
2025-04-28 19:10:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
toBeTypeofNumber() {
|
2025-04-28 19:58:32 +00:00
|
|
|
return this.assertion.customAssertion(
|
|
|
|
(v) => typeof v === 'number',
|
|
|
|
`Expected type to be 'number'`
|
|
|
|
);
|
2025-04-28 19:10:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
toBeTypeofBoolean() {
|
2025-04-28 19:58:32 +00:00
|
|
|
return this.assertion.customAssertion(
|
|
|
|
(v) => typeof v === 'boolean',
|
|
|
|
`Expected type to be 'boolean'`
|
|
|
|
);
|
2025-04-28 19:10:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
toBeTypeOf(typeName: string) {
|
2025-04-28 19:58:32 +00:00
|
|
|
return this.assertion.customAssertion(
|
|
|
|
(v) => typeof v === typeName,
|
|
|
|
`Expected type to be '${typeName}'`
|
|
|
|
);
|
2025-04-28 19:10:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
toBeDefined() {
|
2025-04-28 19:58:32 +00:00
|
|
|
return this.assertion.customAssertion(
|
|
|
|
(v) => v !== undefined,
|
|
|
|
`Expected value to be defined`
|
|
|
|
);
|
2025-04-28 19:10:27 +00:00
|
|
|
}
|
|
|
|
}
|