@@ -24,6 +24,7 @@ import {
2424
2525import { ExpectError , isJestError } from './matcherHint' ;
2626import {
27+ computeMatcherTitleSuffix ,
2728 toBeAttached ,
2829 toBeChecked ,
2930 toBeDisabled ,
@@ -55,7 +56,7 @@ import {
5556 toPass
5657} from './matchers' ;
5758import { toMatchAriaSnapshot } from './toMatchAriaSnapshot' ;
58- import { toHaveScreenshot , toHaveScreenshotStepTitle , toMatchSnapshot } from './toMatchSnapshot' ;
59+ import { toHaveScreenshot , toMatchSnapshot } from './toMatchSnapshot' ;
5960import {
6061 INVERTED_COLOR ,
6162 RECEIVED_COLOR ,
@@ -114,7 +115,7 @@ export const printReceivedStringContainExpectedResult = (
114115type ExpectMessage = string | { message ?: string } ;
115116
116117function createMatchers ( actual : unknown , info : ExpectMetaInfo , prefix : string [ ] ) : any {
117- return new Proxy ( expectLibrary ( actual ) , new ExpectMetaInfoProxyHandler ( info , prefix ) ) ;
118+ return new Proxy ( expectLibrary ( actual ) , new ExpectMetaInfoProxyHandler ( actual , info , prefix ) ) ;
118119}
119120
120121const userMatchersSymbol = Symbol ( 'userMatchers' ) ;
@@ -300,10 +301,12 @@ type ExpectMetaInfo = {
300301} ;
301302
302303class ExpectMetaInfoProxyHandler implements ProxyHandler < any > {
304+ private _actual : any ;
303305 private _info : ExpectMetaInfo ;
304306 private _prefix : string [ ] ;
305307
306- constructor ( info : ExpectMetaInfo , prefix : string [ ] ) {
308+ constructor ( actual : any , info : ExpectMetaInfo , prefix : string [ ] ) {
309+ this . _actual = actual ;
307310 this . _info = { ...info } ;
308311 this . _prefix = prefix ;
309312 }
@@ -344,11 +347,11 @@ class ExpectMetaInfoProxyHandler implements ProxyHandler<any> {
344347 return matcher . call ( target , ...args ) ;
345348
346349 const customMessage = this . _info . message || '' ;
347- const argsSuffix = computeArgsSuffix ( matcherName , args ) ;
348-
349- const defaultTitle = ` ${ this . _info . poll ? 'poll ' : '' } ${ this . _info . isSoft ? 'soft ' : '' } ${ this . _info . isNot ? 'not ' : '' } ${ matcherName } ${ argsSuffix } `;
350- const title = customMessage || `Expect ${ escapeWithQuotes ( defaultTitle , '"' ) } ` ;
351- const apiName = `expect${ this . _info . poll ? '.poll ' : '' } ${ this . _info . isSoft ? '.soft ' : '' } ${ this . _info . isNot ? '.not' : '' } .${ matcherName } ${ argsSuffix } ` ;
350+ const suffixes = computeMatcherTitleSuffix ( matcherName , this . _actual , args ) ;
351+ const defaultTitle = ` ${ this . _info . poll ? 'poll ' : '' } ${ this . _info . isSoft ? 'soft ' : '' } ${ this . _info . isNot ? 'not ' : '' } ${ matcherName } ${ suffixes . short || '' } ` ;
352+ const shortTitle = customMessage || `Expect ${ escapeWithQuotes ( defaultTitle , '"' ) } `;
353+ const longTitle = shortTitle + ( suffixes . long || '' ) ;
354+ const apiName = `expect${ this . _info . poll ? '.poll ' : '' } ${ this . _info . isSoft ? '.soft ' : '' } ${ this . _info . isNot ? '.not' : '' } .${ matcherName } ${ suffixes . short || '' } ` ;
352355
353356 // This looks like it is unnecessary, but it isn't - we need to filter
354357 // out all the frames that belong to the test runner from caught runtime errors.
@@ -359,7 +362,8 @@ class ExpectMetaInfoProxyHandler implements ProxyHandler<any> {
359362 const stepInfo = {
360363 category : 'expect' as const ,
361364 apiName,
362- title,
365+ title : longTitle ,
366+ shortTitle,
363367 params : args [ 0 ] ? { expected : args [ 0 ] } : undefined ,
364368 infectParentStepsWithError : this . _info . isSoft ,
365369 } ;
@@ -443,13 +447,6 @@ async function pollMatcher(qualifiedMatcherName: string, info: ExpectMetaInfo, p
443447 }
444448}
445449
446- function computeArgsSuffix ( matcherName : string , args : any [ ] ) {
447- let value = '' ;
448- if ( matcherName === 'toHaveScreenshot' )
449- value = toHaveScreenshotStepTitle ( ...args ) ;
450- return value ? `(${ value } )` : '' ;
451- }
452-
453450export const expect : Expect < { } > = createExpect ( { } , [ ] , { } ) . extend ( customMatchers ) ;
454451
455452export function mergeExpects ( ...expects : any [ ] ) {
0 commit comments