1717import { constructURLBasedOnBaseURL , isRegExp , isString , isTextualMimeType , pollAgainstDeadline , serializeExpectedTextValues } from 'playwright-core/lib/utils' ;
1818import { colors } from 'playwright-core/lib/utils' ;
1919
20- import { callLogText , expectTypes } from '../util' ;
20+ import { expectTypes } from '../util' ;
2121import { toBeTruthy } from './toBeTruthy' ;
2222import { toEqual } from './toEqual' ;
2323import { toHaveURLWithPredicate } from './toHaveURL' ;
2424import { toMatchText } from './toMatchText' ;
2525import { takeFirst } from '../common/config' ;
2626import { currentTestInfo } from '../common/globals' ;
2727import { TestInfoImpl } from '../worker/testInfo' ;
28+ import { formatMatcherMessage } from './matcherHint' ;
2829
2930import type { ExpectMatcherState } from '../../types/test' ;
3031import type { TestStepInfoImpl } from '../worker/testInfo' ;
@@ -187,7 +188,7 @@ export function toContainText(
187188 return toMatchText . call ( this , 'toContainText' , locator , 'Locator' , async ( isNot , timeout ) => {
188189 const expectedText = serializeExpectedTextValues ( [ expected ] , { matchSubstring : true , normalizeWhiteSpace : true , ignoreCase : options . ignoreCase } ) ;
189190 return await locator . _expect ( 'to.have.text' , { expectedText, isNot, useInnerText : options . useInnerText , timeout } ) ;
190- } , expected , options ) ;
191+ } , expected , { ... options , matchSubstring : true } ) ;
191192 }
192193}
193194
@@ -262,7 +263,7 @@ export function toHaveClass(
262263 return toEqual . call ( this , 'toHaveClass' , locator , 'Locator' , async ( isNot , timeout ) => {
263264 const expectedText = serializeExpectedTextValues ( expected ) ;
264265 return await locator . _expect ( 'to.have.class.array' , { expectedText, isNot, timeout } ) ;
265- } , expected , options , true ) ;
266+ } , expected , options ) ;
266267 } else {
267268 return toMatchText . call ( this , 'toHaveClass' , locator , 'Locator' , async ( isNot , timeout ) => {
268269 const expectedText = serializeExpectedTextValues ( [ expected ] ) ;
@@ -283,7 +284,7 @@ export function toContainClass(
283284 return toEqual . call ( this , 'toContainClass' , locator , 'Locator' , async ( isNot , timeout ) => {
284285 const expectedText = serializeExpectedTextValues ( expected ) ;
285286 return await locator . _expect ( 'to.contain.class.array' , { expectedText, isNot, timeout } ) ;
286- } , expected , options , true ) ;
287+ } , expected , options ) ;
287288 } else {
288289 if ( isRegExp ( expected ) )
289290 throw new Error ( `"expected" argument in toContainClass cannot be a RegExp value` ) ;
@@ -408,7 +409,7 @@ export function toHaveTitle(
408409 return toMatchText . call ( this , 'toHaveTitle' , page , 'Page' , async ( isNot , timeout ) => {
409410 const expectedText = serializeExpectedTextValues ( [ expected ] , { normalizeWhiteSpace : true } ) ;
410411 return await ( page . mainFrame ( ) as FrameEx ) . _expect ( 'to.have.title' , { expectedText, isNot, timeout } ) ;
411- } , expected , { receiverLabel : 'page' , ... options } ) ;
412+ } , expected , options ) ;
412413}
413414
414415export function toHaveURL (
@@ -426,7 +427,7 @@ export function toHaveURL(
426427 return toMatchText . call ( this , 'toHaveURL' , page , 'Page' , async ( isNot , timeout ) => {
427428 const expectedText = serializeExpectedTextValues ( [ expected ] , { ignoreCase : options ?. ignoreCase } ) ;
428429 return await ( page . mainFrame ( ) as FrameEx ) . _expect ( 'to.have.url' , { expectedText, isNot, timeout } ) ;
429- } , expected , { receiverLabel : 'page' , ... options } ) ;
430+ } , expected , options ) ;
430431}
431432
432433export async function toBeOK (
@@ -443,9 +444,12 @@ export async function toBeOK(
443444 isTextEncoding ? response . text ( ) : null
444445 ] ) : [ ] ;
445446
446- const message = ( ) => this . utils . matcherHint ( matcherName , undefined , '' , { isNot : this . isNot } ) +
447- callLogText ( log ) +
448- ( text === null ? '' : `\nResponse text:\n${ colors . dim ( text ?. substring ( 0 , 1000 ) || '' ) } ` ) ;
447+ const message = ( ) => formatMatcherMessage ( this , {
448+ matcherName,
449+ receiver : 'response' ,
450+ expectation : '' ,
451+ log,
452+ } ) + ( text === null ? '' : `\nResponse text:\n${ colors . dim ( text ?. substring ( 0 , 1000 ) || '' ) } ` ) ;
449453
450454 const pass = response . ok ( ) ;
451455 return { message, pass } ;
0 commit comments