@thisisagile/easy-test
Version:
Straightforward library for testing microservices built with @thisisagile/easy
26 lines (22 loc) • 690 B
text/typescript
import { match } from './Match';
import { asString } from '../utils/Utils';
export const toMatchText = (value?: unknown, text?: unknown): jest.CustomMatcherResult =>
match<unknown>(value)
.undefined(v => v, 'Subject is undefined.')
.undefined(() => text, 'Text to match with is undefined.')
.not(
v => asString(v) === asString(text),
v => `Text '${v}' does not match with text '${text}'.`
)
.else(v => `Text '${v}' matches`);
expect.extend({
toMatchText: toMatchText,
});
declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace jest {
interface Matchers<R, T> {
toMatchText(text?: unknown): R;
}
}
}