Files
upstream-jitsi-meet/tests/helpers/matchers.ts
upstream-mirror 1d2bfcac0c
Some checks failed
Prosody Plugin Tests / test (push) Failing after 10m11s
Close stale issues and PRs / stale (push) Failing after 1s
snapshot of https://github.com/jitsi/jitsi-meet.git @ fd1749dd28f4138aa80234fc7f311b19aaffa0e7 (2026-09-15)
2026-09-15 15:56:32 +05:00

49 lines
2.1 KiB
TypeScript

// Register custom matchers on the global expect set up by @wdio/runner during _initSession.
// Must be called from a wdio config hook that runs after _initSession (e.g. `before`); calling
// at module load extends a stale `globalThis.expect` that gets replaced before tests run.
export function registerCustomMatchers(): void {
expect.extend({
toPartiallyMatch(received: string, other: string, receivedLabel = 'received', otherLabel = 'other') {
const pass = received.includes(other) || other.includes(received);
return {
pass,
message: () => pass
? `Expected ${receivedLabel} NOT to partially match ${otherLabel}.\n ${receivedLabel}: "${received}"\n ${otherLabel}: "${other}"`
: `Expected ${receivedLabel} to partially match ${otherLabel} (one should contain the other).\n ${receivedLabel}: "${received}"\n ${otherLabel}: "${other}"`
};
},
toStartWith(received: string, prefix: string, label = 'value') {
const pass = received.startsWith(prefix);
return {
pass,
message: () => pass
? `Expected ${label} NOT to start with "${prefix}".\n ${label}: "${received}"`
: `Expected ${label} to start with "${prefix}".\n ${label}: "${received}"`
};
},
toBeInteger(received: unknown, label = 'value') {
const pass = Number.isInteger(received);
return {
pass,
message: () => pass
? `Expected ${label} NOT to be an integer.\n ${label}: ${JSON.stringify(received)}`
: `Expected ${label} to be an integer.\n ${label}: ${JSON.stringify(received)}`
};
}
});
}
declare module 'expect' {
// eslint-disable-next-line @typescript-eslint/naming-convention
interface Matchers<R> {
toBeInteger: (label?: string) => R;
toPartiallyMatch: (other: string, receivedLabel?: string, otherLabel?: string) => R;
toStartWith: (prefix: string, label?: string) => R;
}
}