Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(test): allow any return type for test body (#40852)

Sebastian Landwehrbb7af07608e5
diff --git a/packages/playwright/types/test.d.ts b/packages/playwright/types/test.d.ts
index ce67a74db6..34651bff3b 100644
--- a/packages/playwright/types/test.d.ts
+++ b/packages/playwright/types/test.d.ts
@@ -2689,7 +2689,7 @@ export type TestDetails = {
annotation?: TestDetailsAnnotation | TestDetailsAnnotation[];
}
-type TestBody<TestArgs> = (args: TestArgs, testInfo: TestInfo) => Promise<void> | void;
+type TestBody<TestArgs> = (args: TestArgs, testInfo: TestInfo) => Promise<unknown> | unknown;
type ConditionBody<TestArgs> = (args: TestArgs) => boolean;
/**
diff --git a/tests/playwright-test/types-2.spec.ts b/tests/playwright-test/types-2.spec.ts
index 93b941bd5e..79b36aacdc 100644
--- a/tests/playwright-test/types-2.spec.ts
+++ b/tests/playwright-test/types-2.spec.ts
@@ -108,6 +108,17 @@ test('can return anything from hooks', async ({ runTSC }) => {
expect(result.exitCode).toBe(0);
});
+test('can return anything from test body', async ({ runTSC }) => {
+ const result = await runTSC({
+ 'a.spec.ts': `
+ import { test } from '@playwright/test';
+ test('sync body', () => 123);
+ test('async body', async () => ({ ok: true }));
+ `
+ });
+ expect(result.exitCode).toBe(0);
+});
+
test('test.extend options should check types', async ({ runTSC }) => {
const result = await runTSC({
'helper.ts': `
diff --git a/utils/generate_types/overrides-test.d.ts b/utils/generate_types/overrides-test.d.ts
index f66f4c0039..ac5c365801 100644
--- a/utils/generate_types/overrides-test.d.ts
+++ b/utils/generate_types/overrides-test.d.ts
@@ -100,7 +100,7 @@ export type TestDetails = {
annotation?: TestDetailsAnnotation | TestDetailsAnnotation[];
}
-type TestBody<TestArgs> = (args: TestArgs, testInfo: TestInfo) => Promise<void> | void;
+type TestBody<TestArgs> = (args: TestArgs, testInfo: TestInfo) => Promise<unknown> | unknown;
type ConditionBody<TestArgs> = (args: TestArgs) => boolean;
export interface TestType<TestArgs extends {}, WorkerArgs extends {}> {