Normalize error "expected" text
This commit is contained in:
parent
afd19da215
commit
26d3a77946
|
|
@ -20,7 +20,7 @@ import { colors } from 'playwright-core/lib/utilsBundle';
|
|||
import type { Locator } from 'playwright-core';
|
||||
import { EXPECTED_COLOR } from '../common/expectBundle';
|
||||
|
||||
export function toMatchExpectedVerification(
|
||||
export function toMatchExpectedStringOrPredicateVerification(
|
||||
state: ExpectMatcherState,
|
||||
matcherName: string,
|
||||
receiver: Locator | undefined,
|
||||
|
|
@ -42,7 +42,8 @@ export function toMatchExpectedVerification(
|
|||
const message = supportsPredicate ? 'string, regular expression, or predicate' : 'string or regular expression';
|
||||
|
||||
throw new Error([
|
||||
matcherHint(state, receiver, matcherName, expression, expected, matcherOptions),
|
||||
// Always display `expected` in expectation place
|
||||
matcherHint(state, receiver, matcherName, expression, undefined, matcherOptions),
|
||||
`${colors.bold('Matcher error')}: ${EXPECTED_COLOR('expected',)} value must be a ${message}`,
|
||||
state.utils.printWithType('Expected', expected, state.utils.printExpected)
|
||||
].join('\n\n'));
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ import { TestInfoImpl } from '../worker/testInfo';
|
|||
import type { ExpectMatcherState } from '../../types/test';
|
||||
import { takeFirst } from '../common/config';
|
||||
import { matcherHint } from './matcherHint';
|
||||
import { toMatchExpectedVerification } from './error';
|
||||
import { toMatchExpectedStringOrPredicateVerification } from './error';
|
||||
|
||||
export interface LocatorEx extends Locator {
|
||||
_expect(expression: string, options: FrameExpectParams): Promise<{ matches: boolean, received?: any, log?: string[], timedOut?: boolean }>;
|
||||
|
|
@ -396,7 +396,7 @@ export async function toHaveURL2(
|
|||
) {
|
||||
const matcherName = 'toHaveURL';
|
||||
const expression = 'page';
|
||||
toMatchExpectedVerification(
|
||||
toMatchExpectedStringOrPredicateVerification(
|
||||
this,
|
||||
matcherName,
|
||||
undefined,
|
||||
|
|
@ -429,7 +429,7 @@ export async function toHaveURL2(
|
|||
undefined,
|
||||
matcherName,
|
||||
expression,
|
||||
typeof expected === 'function' ? 'predicate' : expected,
|
||||
undefined,
|
||||
matcherOptions,
|
||||
timeout,
|
||||
),
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import type { ExpectMatcherState } from '../../types/test';
|
|||
import { kNoElementsFoundError, matcherHint } from './matcherHint';
|
||||
import type { MatcherResult } from './matcherHint';
|
||||
import type { Locator } from 'playwright-core';
|
||||
import { toMatchExpectedVerification } from './error';
|
||||
import { toMatchExpectedStringOrPredicateVerification } from './error';
|
||||
|
||||
export async function toMatchText(
|
||||
this: ExpectMatcherState,
|
||||
|
|
@ -36,7 +36,7 @@ export async function toMatchText(
|
|||
options: { timeout?: number, matchSubstring?: boolean } = {},
|
||||
): Promise<MatcherResult<string | RegExp, string>> {
|
||||
expectTypes(receiver, [receiverType], matcherName);
|
||||
toMatchExpectedVerification(this, matcherName, receiver, receiver, expected);
|
||||
toMatchExpectedStringOrPredicateVerification(this, matcherName, receiver, receiver, expected);
|
||||
|
||||
const timeout = options.timeout ?? this.timeout;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue