1414 * limitations under the License. 
1515 */ 
1616
17- import  {  constructURLBasedOnBaseURL ,   urlMatches  }  from  'playwright-core/lib/utils' ; 
17+ import  {  urlMatches  }  from  'playwright-core/lib/utils' ; 
1818import  {  colors  }  from  'playwright-core/lib/utils' ; 
1919
20- import  {  printReceivedStringContainExpectedResult ,   printReceivedStringContainExpectedSubstring  }  from  './expect' ; 
20+ import  {  printReceivedStringContainExpectedResult  }  from  './expect' ; 
2121import  {   matcherHint  }  from  './matcherHint' ; 
2222import  {  EXPECTED_COLOR ,  printReceived  }  from  '../common/expectBundle' ; 
2323
2424import  type  {  MatcherResult  }  from  './matcherHint' ; 
2525import  type  {  ExpectMatcherState  }  from  '../../types/test' ; 
2626import  type  {  Page  }  from  'playwright-core' ; 
2727
28- export  async  function  toHaveURL ( 
28+ export  async  function  toHaveURLWithPredicate ( 
2929  this : ExpectMatcherState , 
3030  page : Page , 
31-   expected : string   |   RegExp   |   ( ( url : URL )  =>  boolean ) , 
31+   expected : ( url : URL )  =>  boolean , 
3232  options ?: {  ignoreCase ?: boolean ;  timeout ?: number  } , 
3333) : Promise < MatcherResult < string  |  RegExp ,  string > >  { 
3434  const  matcherName  =  'toHaveURL' ; 
@@ -38,11 +38,7 @@ export async function toHaveURL(
3838    promise : this . promise , 
3939  } ; 
4040
41-   if  ( 
42-     ! ( typeof  expected  ===  'string' )  && 
43-     ! ( expected  &&  'test'  in  expected  &&  typeof  expected . test  ===  'function' )  && 
44-     ! ( typeof  expected  ===  'function' ) 
45-   )  { 
41+   if  ( typeof  expected  !==  'function' )  { 
4642    throw  new  Error ( 
4743        [ 
4844          // Always display `expected` in expectation place 
@@ -68,9 +64,7 @@ export async function toHaveURL(
6864              urlMatches ( 
6965                  baseURL ?. toLocaleLowerCase ( ) , 
7066                  lastCheckedURLString . toLocaleLowerCase ( ) , 
71-                   typeof  expected  ===  'string' 
72-                     ? expected . toLocaleLowerCase ( ) 
73-                     : expected , 
67+                   expected , 
7468              ) 
7569            ) ; 
7670          } 
@@ -98,9 +92,7 @@ export async function toHaveURL(
9892          this , 
9993          matcherName , 
10094          expression , 
101-           typeof  expected  ===  'string' 
102-             ? constructURLBasedOnBaseURL ( baseURL ,  expected ) 
103-             : expected , 
95+           expected , 
10496          lastCheckedURLString , 
10597          this . isNot , 
10698          true , 
@@ -115,7 +107,7 @@ function toHaveURLMessage(
115107  state : ExpectMatcherState , 
116108  matcherName : string , 
117109  expression : string , 
118-   expected : string   |   RegExp   |   Function , 
110+   expected : Function , 
119111  received : string  |  undefined , 
120112  pass : boolean , 
121113  didTimeout : boolean , 
@@ -136,15 +128,9 @@ function toHaveURLMessage(
136128    printedReceived  =  `Received string: ${ printReceived ( receivedString ) }  ; 
137129  }  else  { 
138130    if  ( pass )  { 
139-       if  ( typeof  expected  ===  'string' )  { 
140-         printedExpected  =  `Expected string: not ${ state . utils . printExpected ( expected ) }  ; 
141-         const  formattedReceived  =  printReceivedStringContainExpectedSubstring ( receivedString ,  receivedString . indexOf ( expected ) ,  expected . length ) ; 
142-         printedReceived  =  `Received string: ${ formattedReceived }  ; 
143-       }  else  { 
144-         printedExpected  =  `Expected pattern: not ${ state . utils . printExpected ( expected ) }  ; 
145-         const  formattedReceived  =  printReceivedStringContainExpectedResult ( receivedString ,  typeof  expected . exec  ===  'function'  ? expected . exec ( receivedString )  : null ) ; 
146-         printedReceived  =  `Received string: ${ formattedReceived }  ; 
147-       } 
131+       printedExpected  =  `Expected pattern: not ${ state . utils . printExpected ( expected ) }  ; 
132+       const  formattedReceived  =  printReceivedStringContainExpectedResult ( receivedString ,  null ) ; 
133+       printedReceived  =  `Received string: ${ formattedReceived }  ; 
148134    }  else  { 
149135      const  labelExpected  =  `Expected ${ typeof  expected  ===  'string'  ? 'string'  : 'pattern' }  ; 
150136      printedDiff  =  state . utils . printDiffOrStringify ( expected ,  receivedString ,  labelExpected ,  'Received string' ,  false ) ; 
0 commit comments