diff --git a/docs/src/test-api/class-test.md b/docs/src/test-api/class-test.md index 5864f04eab..d6f1d87513 100644 --- a/docs/src/test-api/class-test.md +++ b/docs/src/test-api/class-test.md @@ -1779,8 +1779,9 @@ Maximum time in milliseconds for the step to finish. Defaults to `0` (no timeout Marks a test step as "should fail". Playwright runs this test step and ensures that it actually fails. This is useful for documentation purposes to acknowledge that some functionality is broken until it is fixed. -To declare a "failing" step: -* `test.step.fail(title, body)` +:::note +If the step exceeds the timeout, a [TimeoutError] is thrown. This indicates the step did not fail as expected. +::: **Usage** @@ -1791,7 +1792,7 @@ import { test, expect } from '@playwright/test'; test('my test', async ({ page }) => { // ... - await test.step.fail('not yet ready', async () => { + await test.step.fail('currently failing', async () => { // ... }); }); @@ -1833,9 +1834,6 @@ Maximum time in milliseconds for the step to finish. Defaults to `0` (no timeout Mark a test step as "fixme", with the intention to fix it. Playwright will not run the step. -To declare a "fixme" step: -* `test.step.fixme(title, body)` - **Usage** You can declare a test step as failing, so that Playwright ensures it actually fails. diff --git a/packages/playwright/types/test.d.ts b/packages/playwright/types/test.d.ts index 1f04b937de..caed95b8d5 100644 --- a/packages/playwright/types/test.d.ts +++ b/packages/playwright/types/test.d.ts @@ -5714,9 +5714,6 @@ export interface TestType { /** * Mark a test step as "fixme", with the intention to fix it. Playwright will not run the step. * - * To declare a "fixme" step: - * - `test.step.fixme(title, body)` - * * **Usage** * * You can declare a test step as failing, so that Playwright ensures it actually fails. @@ -5736,13 +5733,13 @@ export interface TestType { * @param body Step body. * @param options */ - fixme(title: string, body: () => void | Promise, options?: { box?: boolean, location?: Location, timeout?: number }): Promise; + fixme(title: string, body: () => any | Promise, options?: { box?: boolean, location?: Location, timeout?: number }): Promise; /** * Marks a test step as "should fail". Playwright runs this test step and ensures that it actually fails. This is * useful for documentation purposes to acknowledge that some functionality is broken until it is fixed. * - * To declare a "failing" step: - * - `test.step.fail(title, body)` + * **NOTE** If the step exceeds the timeout, a [TimeoutError](https://playwright.dev/docs/api/class-timeouterror) is + * thrown. This indicates the step did not fail as expected. * * **Usage** * @@ -5753,7 +5750,7 @@ export interface TestType { * * test('my test', async ({ page }) => { * // ... - * await test.step.fail('not yet ready', async () => { + * await test.step.fail('currently failing', async () => { * // ... * }); * }); @@ -5763,7 +5760,7 @@ export interface TestType { * @param body Step body. * @param options */ - fail(title: string, body: () => void | Promise, options?: { box?: boolean, location?: Location, timeout?: number }): Promise; + fail(title: string, body: () => any | Promise, options?: { box?: boolean, location?: Location, timeout?: number }): Promise; } /** * `expect` function can be used to create test assertions. Read more about [test assertions](https://playwright.dev/docs/test-assertions). diff --git a/tests/playwright-test/test-step.spec.ts b/tests/playwright-test/test-step.spec.ts index 159f5244e6..74448ccbf8 100644 --- a/tests/playwright-test/test-step.spec.ts +++ b/tests/playwright-test/test-step.spec.ts @@ -1519,7 +1519,7 @@ test('test.step.fail and test.step.fixme should work', async ({ runInlineTest }) }); }); ` - }, { reporter: '', workers: 1, timeout: 3000 }); + }, { reporter: '' }); expect(result.exitCode).toBe(0); expect(result.report.stats.expected).toBe(1); @@ -1553,7 +1553,7 @@ test('timeout inside test.step.fail is an error', async ({ runInlineTest }) => { }); }); ` - }, { reporter: '', workers: 2, timeout: 1000 }); + }, { reporter: '', timeout: 2500 }); expect(result.exitCode).toBe(1); expect(result.report.stats.unexpected).toBe(1); @@ -1563,7 +1563,7 @@ test.step |outer step 2 @ a.test.ts:4 test.step | inner step 2 @ a.test.ts:5 hook |After Hooks hook |Worker Cleanup - |Test timeout of 1000ms exceeded. + |Test timeout of 2500ms exceeded. `); }); @@ -1583,7 +1583,7 @@ test('skip test.step.fixme body', async ({ runInlineTest }) => { expect(didRun).toBe(false); }); ` - }, { reporter: '', workers: 1, timeout: 1000 }); + }, { reporter: '' }); expect(result.exitCode).toBe(0); expect(result.report.stats.expected).toBe(1); diff --git a/tests/playwright-test/types-2.spec.ts b/tests/playwright-test/types-2.spec.ts index 7db452c66e..3a06ed0da2 100644 --- a/tests/playwright-test/types-2.spec.ts +++ b/tests/playwright-test/types-2.spec.ts @@ -212,20 +212,16 @@ test('step.fail and step.fixme return void ', async ({ runTSC }) => { test('test step.fail', async ({ }) => { // @ts-expect-error const bad1: string = await test.step.fail('my step', () => { }); - // @ts-expect-error - const bad2: void = await test.step.fail('my step', async () => { - return 10; + const good: void = await test.step.fail('my step', async () => { + return 2024; }); - const good: void = await test.step.fail('my step', async () => { }); }); test('test step.fixme', async ({ }) => { // @ts-expect-error const bad1: string = await test.step.fixme('my step', () => { }); - // @ts-expect-error - const bad2: void = await test.step.fixme('my step', async () => { - return 10; + const good: void = await test.step.fixme('my step', async () => { + return 2024; }); - const good: void = await test.step.fixme('my step', async () => { }); }); ` }); diff --git a/utils/generate_types/overrides-test.d.ts b/utils/generate_types/overrides-test.d.ts index 6f89ca9349..3370103a25 100644 --- a/utils/generate_types/overrides-test.d.ts +++ b/utils/generate_types/overrides-test.d.ts @@ -164,8 +164,8 @@ export interface TestType { use(fixtures: Fixtures<{}, {}, TestArgs, WorkerArgs>): void; step: { (title: string, body: () => T | Promise, options?: { box?: boolean, location?: Location, timeout?: number }): Promise; - fixme(title: string, body: () => void | Promise, options?: { box?: boolean, location?: Location, timeout?: number }): Promise; - fail(title: string, body: () => void | Promise, options?: { box?: boolean, location?: Location, timeout?: number }): Promise; + fixme(title: string, body: () => any | Promise, options?: { box?: boolean, location?: Location, timeout?: number }): Promise; + fail(title: string, body: () => any | Promise, options?: { box?: boolean, location?: Location, timeout?: number }): Promise; } expect: Expect<{}>; extend(fixtures: Fixtures): TestType;