* toHavePathNameEndingWith allows checking the end of the URL (ie. to make * sure we redirected to a specific page) without caring about the entire URL, * which might depend on things like whether or not organizations or other * features are enabled.
( page: Page, expected: string, options?: PollingOptions, )
| 43 | * features are enabled. |
| 44 | */ |
| 45 | async toHavePathNameEndingWith( |
| 46 | page: Page, |
| 47 | expected: string, |
| 48 | options?: PollingOptions, |
| 49 | ) { |
| 50 | let actual: string = new URL(page.url()).pathname; |
| 51 | let pass: boolean; |
| 52 | try { |
| 53 | await expect |
| 54 | .poll(() => { |
| 55 | actual = new URL(page.url()).pathname; |
| 56 | return actual.endsWith(expected); |
| 57 | }, options) |
| 58 | .toBe(true); |
| 59 | pass = true; |
| 60 | } catch { |
| 61 | pass = false; |
| 62 | } |
| 63 | |
| 64 | return { |
| 65 | name: "toHavePathNameEndingWith", |
| 66 | pass, |
| 67 | actual, |
| 68 | expected, |
| 69 | message: () => |
| 70 | `The page does not have the expected URL pathname.\nExpected a url ${ |
| 71 | this.isNot ? "not " : "" |
| 72 | }ending with: ${this.utils.printExpected( |
| 73 | expected, |
| 74 | )}\nActual: ${this.utils.printReceived(actual)}`, |
| 75 | }; |
| 76 | }, |
| 77 | }); |