mirror of
https://github.com/microsoft/playwright.git
synced 2025-01-05 19:04:43 +03:00
fix(expect): mark step as failed when async custom matcher throws (#23035)
Fixes #23021.
This commit is contained in:
parent
bf1df9678f
commit
f469e4b1eb
@ -312,6 +312,8 @@ class ExpectMetaInfoProxyHandler implements ProxyHandler<any> {
|
||||
} else {
|
||||
try {
|
||||
const result = matcher.call(target, ...args);
|
||||
if (result instanceof Promise)
|
||||
return result.then(finalizer).catch(reportStepError);
|
||||
finalizer();
|
||||
return result;
|
||||
} catch (e) {
|
||||
|
@ -480,7 +480,7 @@ test('should report custom expect steps', async ({ runInlineTest }) => {
|
||||
'reporter.ts': stepHierarchyReporter,
|
||||
'playwright.config.ts': `
|
||||
module.exports = {
|
||||
reporter: './reporter',
|
||||
reporter: [['./reporter'], ['line']],
|
||||
};
|
||||
`,
|
||||
'a.test.ts': `
|
||||
@ -501,16 +501,27 @@ test('should report custom expect steps', async ({ runInlineTest }) => {
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
async toBeFailingAsync(received) {
|
||||
await new Promise(f => setTimeout(f, 0));
|
||||
return {
|
||||
message: () => "It fails!",
|
||||
pass: false,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
import { test, expect } from '@playwright/test';
|
||||
test('pass', async ({}) => {
|
||||
test('fail', async ({}) => {
|
||||
expect(15).toBeWithinRange(10, 20);
|
||||
await expect(1).toBeFailingAsync(22);
|
||||
});
|
||||
`
|
||||
}, { reporter: '', workers: 1 });
|
||||
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(result.exitCode).toBe(1);
|
||||
expect(result.failed).toBe(1);
|
||||
expect(result.output).toContain('It fails!');
|
||||
const objects = result.outputLines.map(line => JSON.parse(line));
|
||||
expect(objects).toEqual([
|
||||
{
|
||||
@ -526,6 +537,16 @@ test('should report custom expect steps', async ({ runInlineTest }) => {
|
||||
},
|
||||
title: 'expect.toBeWithinRange',
|
||||
},
|
||||
{
|
||||
category: 'expect',
|
||||
location: {
|
||||
column: 'number',
|
||||
file: 'a.test.ts',
|
||||
line: 'number',
|
||||
},
|
||||
title: 'expect.toBeFailingAsync',
|
||||
error: '<error>',
|
||||
},
|
||||
{
|
||||
category: 'hook',
|
||||
title: 'After Hooks',
|
||||
|
Loading…
Reference in New Issue
Block a user