File tree 1 file changed +16
-13
lines changed 1 file changed +16
-13
lines changed Original file line number Diff line number Diff line change 1
- import { expect , type Page , waitFor } from "@playwright/test" ;
1
+ import { expect , type Page } from "@playwright/test" ;
2
2
3
- export const expectUrl = expect . extend ( {
4
- async toHavePath ( page : Page , pathname : string ) {
5
- let url ;
6
- let pass ;
3
+ type PollingOptions = { timeout ?: number ; intervals ?: number [ ] } ;
7
4
5
+ export const expectUrl = expect . extend ( {
6
+ /**
7
+ * toHavePathName is an alternative to `toHaveURL` that won't fail if the URL contains query parameters.
8
+ */
9
+ async toHavePathName ( page : Page , expected : string , options ?: PollingOptions ) {
10
+ let actual : string = new URL ( page . url ( ) ) . pathname ;
11
+ let pass : boolean ;
8
12
try {
9
- await waitFor ( ( ) => {
10
- url = new URL ( page . url ( ) ) ;
11
- expect ( url . pathname ) . toBe ( pathname ) ;
12
- } ) ;
13
+ expect
14
+ . poll ( ( ) => ( actual = new URL ( page . url ( ) ) . pathname ) , options )
15
+ . toBe ( expected ) ;
13
16
pass = true ;
14
17
} catch {
15
18
pass = false ;
16
19
}
17
20
18
21
return {
19
- message : ( ) => "foob ",
22
+ name : "toHavePathName ",
20
23
pass,
21
- name : "toHavePath" ,
22
- expected : pathname ,
23
- actual : url . toString ( ) ,
24
+ actual ,
25
+ expected,
26
+ message : ( ) => "The page does not have the expected URL pathname." ,
24
27
} ;
25
28
} ,
26
29
} ) ;
You can’t perform that action at this time.
0 commit comments