diff --git a/packages/playwright/src/matchers/error.ts b/packages/playwright/src/matchers/error.ts index 13e01c4887..5bcff78636 100644 --- a/packages/playwright/src/matchers/error.ts +++ b/packages/playwright/src/matchers/error.ts @@ -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')); diff --git a/packages/playwright/src/matchers/matchers.ts b/packages/playwright/src/matchers/matchers.ts index cf79957949..00f67a0178 100644 --- a/packages/playwright/src/matchers/matchers.ts +++ b/packages/playwright/src/matchers/matchers.ts @@ -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, ), diff --git a/packages/playwright/src/matchers/toMatchText.ts b/packages/playwright/src/matchers/toMatchText.ts index 650905163a..251da7e84c 100644 --- a/packages/playwright/src/matchers/toMatchText.ts +++ b/packages/playwright/src/matchers/toMatchText.ts @@ -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> { expectTypes(receiver, [receiverType], matcherName); - toMatchExpectedVerification(this, matcherName, receiver, receiver, expected); + toMatchExpectedStringOrPredicateVerification(this, matcherName, receiver, receiver, expected); const timeout = options.timeout ?? this.timeout;