diff --git a/packages/playwright-test/src/matchers/matchers.ts b/packages/playwright-test/src/matchers/matchers.ts index 6dd5c658ba718..6a579e066c3fb 100644 --- a/packages/playwright-test/src/matchers/matchers.ts +++ b/packages/playwright-test/src/matchers/matchers.ts @@ -352,5 +352,7 @@ export async function toPass( return { message, pass: this.isNot }; } + if (testStateBeforeToPassMatcher && testInfo) + testInfo._restoreErrorState(testStateBeforeToPassMatcher); return { pass: !this.isNot, message: () => '' }; } diff --git a/tests/playwright-test/expect-to-pass.spec.ts b/tests/playwright-test/expect-to-pass.spec.ts index d5d9937e57f1d..9096c24e393ca 100644 --- a/tests/playwright-test/expect-to-pass.spec.ts +++ b/tests/playwright-test/expect-to-pass.spec.ts @@ -183,6 +183,24 @@ test('should swallow all soft errors inside toPass matcher, if successful', asyn expect(result.failed).toBe(1); }); +test('should work with no.toPass and failing soft assertion', async ({ runInlineTest }) => { + test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/20518' }); + + const result = await runInlineTest({ + 'a.spec.ts': ` + const { test } = pwt; + test('should work', async () => { + await test.expect(() => { + expect.soft(1).toBe(2); + }).not.toPass({ timeout: 1000 }); + }); + ` + }); + expect(result.exitCode).toBe(0); + expect(result.failed).toBe(0); + expect(result.passed).toBe(1); +}); + test('should show only soft errors on last toPass pass', async ({ runInlineTest }) => { const result = await runInlineTest({ 'a.spec.ts': `