fix(assertion-matchers): Refactor matcher implementations to consistently use customAssertion for improved consistency and clarity.
This commit is contained in:
@ -7,26 +7,44 @@ export class StringMatchers {
|
||||
constructor(private assertion: Assertion<string>) {}
|
||||
|
||||
toStartWith(prefix: string) {
|
||||
return this.assertion.toStartWith(prefix);
|
||||
return this.assertion.customAssertion(
|
||||
(value) => (value as string).startsWith(prefix),
|
||||
`Expected string to start with "${prefix}"`
|
||||
);
|
||||
}
|
||||
|
||||
toEndWith(suffix: string) {
|
||||
return this.assertion.toEndWith(suffix);
|
||||
return this.assertion.customAssertion(
|
||||
(value) => (value as string).endsWith(suffix),
|
||||
`Expected string to end with "${suffix}"`
|
||||
);
|
||||
}
|
||||
|
||||
toInclude(substring: string) {
|
||||
return this.assertion.toInclude(substring);
|
||||
return this.assertion.customAssertion(
|
||||
(value) => (value as string).includes(substring),
|
||||
`Expected string to include "${substring}"`
|
||||
);
|
||||
}
|
||||
|
||||
toMatch(regex: RegExp) {
|
||||
return this.assertion.toMatch(regex);
|
||||
return this.assertion.customAssertion(
|
||||
(value) => regex.test(value as string),
|
||||
`Expected string to match ${regex}`
|
||||
);
|
||||
}
|
||||
|
||||
toBeOneOf(values: string[]) {
|
||||
return this.assertion.toBeOneOf(values);
|
||||
return this.assertion.customAssertion(
|
||||
(value) => (values as string[]).includes(value as string),
|
||||
`Expected string to be one of ${JSON.stringify(values)}`
|
||||
);
|
||||
}
|
||||
/** Length check for strings */
|
||||
toHaveLength(length: number) {
|
||||
return this.assertion.toHaveLength(length);
|
||||
return this.assertion.customAssertion(
|
||||
(value) => (value as string).length === length,
|
||||
`Expected string to have length ${length}`
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user