diff --git a/tests/page/expect-misc.spec.ts b/tests/page/expect-misc.spec.ts
index a1fb6637b1..5534f16078 100644
--- a/tests/page/expect-misc.spec.ts
+++ b/tests/page/expect-misc.spec.ts
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+import { stripVTControlCharacters } from 'node:util';
import { stripAnsi } from '../config/utils';
import { test, expect } from './pageTest';
@@ -243,7 +244,15 @@ test.describe('toHaveURL', () => {
test('fail', async ({ page }) => {
await page.goto('data:text/html,
B
');
const error = await expect(page).toHaveURL('wrong', { timeout: 1000 }).catch(e => e);
- expect(error.message).toContain('expect.toHaveURL with timeout 1000ms');
+ expect(stripVTControlCharacters(error.message)).toContain('Timed out 1000ms waiting for expect(page).toHaveURL(expected)');
+ });
+
+ test('fail with invalid argument', async ({ page }) => {
+ await page.goto('data:text/html,B
');
+ // @ts-expect-error
+ const error = await expect(page).toHaveURL({}).catch(e => e);
+ expect(stripVTControlCharacters(error.message)).toContain('expect(page).toHaveURL(expected)\n\n\nMatcher error: expected value should be a string, regular expression, or predicate');
+ expect(stripVTControlCharacters(error.message)).toContain('Expected has type: object\nExpected has value: {}');
});
test('support ignoreCase', async ({ page }) => {
diff --git a/tests/playwright-test/expect.spec.ts b/tests/playwright-test/expect.spec.ts
index c35cdd7c09..dfe6a6cf02 100644
--- a/tests/playwright-test/expect.spec.ts
+++ b/tests/playwright-test/expect.spec.ts
@@ -556,6 +556,24 @@ test('should respect expect.timeout', async ({ runInlineTest }) => {
expect(result.passed).toBe(1);
});
+test('should support toHaveURL predicate', async ({ runInlineTest }) => {
+ const result = await runInlineTest({
+ 'playwright.config.js': `module.exports = { expect: { timeout: 1000 } }`,
+ 'a.test.ts': `
+ import { test, expect } from '@playwright/test';
+
+ test('predicate', async ({ page }) => {
+ await page.goto('data:text/html,A
');
+ const error = await expect(page).toHaveURL('data:text/html,B
').catch(e => e);
+ expect(error.message).toContain('expect.toHaveURL with timeout 1000ms');
+ expect(error.message).toContain('data:text/html,');
+ });
+ `,
+ }, { workers: 1 });
+ expect(result.exitCode).toBe(0);
+ expect(result.passed).toBe(1);
+});
+
test('should log scale the time', async ({ runInlineTest }) => {
const result = await runInlineTest({
'a.test.ts': `