fix: handle not.toPass() with expect.soft inside (#20596)

Fixes #20518
This commit is contained in:
Andrey Lushnikov 2023-02-03 09:14:05 -08:00 committed by GitHub
parent ffb719385b
commit f45f20a8c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View File

@ -352,5 +352,7 @@ export async function toPass(
return { message, pass: this.isNot };
}
if (testStateBeforeToPassMatcher && testInfo)
testInfo._restoreErrorState(testStateBeforeToPassMatcher);
return { pass: !this.isNot, message: () => '' };
}

View File

@ -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': `