From d10cc91cf6a4bc8f633ea33a44d7c683a95083eb Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Tue, 20 Dec 2022 08:41:32 -0800 Subject: [PATCH] cherry-pick(#19580): fix: properly handle negated timed-out `toPass` matcher --- packages/playwright-test/src/matchers/matchers.ts | 2 +- tests/playwright-test/expect-to-pass.spec.ts | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/playwright-test/src/matchers/matchers.ts b/packages/playwright-test/src/matchers/matchers.ts index 3d39c390fb0da..b9477377e340c 100644 --- a/packages/playwright-test/src/matchers/matchers.ts +++ b/packages/playwright-test/src/matchers/matchers.ts @@ -358,5 +358,5 @@ export async function toPass( `- ${timeoutMessage}`, ].join('\n') : timeoutMessage; - return { message, pass: false }; + return { message, pass: isNot ? true : false }; } diff --git a/tests/playwright-test/expect-to-pass.spec.ts b/tests/playwright-test/expect-to-pass.spec.ts index d76cf094c1f61..82f630843805e 100644 --- a/tests/playwright-test/expect-to-pass.spec.ts +++ b/tests/playwright-test/expect-to-pass.spec.ts @@ -166,4 +166,17 @@ test('should work with soft', async ({ runInlineTest }) => { expect(stripAnsi(result.output)).toContain('Received: 2'); expect(result.exitCode).toBe(1); expect(result.failed).toBe(1); -}); \ No newline at end of file +}); + +test('should not accept TimeoutError', async ({ runInlineTest }) => { + const result = await runInlineTest({ + 'a.spec.ts': ` + const { test } = pwt; + test('should fail', async () => { + await test.expect(() => {}).not.toPass({ timeout: 1 }); + }); + ` + }); + expect(result.exitCode).toBe(1); + expect(result.failed).toBe(1); +});