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 {
|
} else {
|
||||||
try {
|
try {
|
||||||
const result = matcher.call(target, ...args);
|
const result = matcher.call(target, ...args);
|
||||||
|
if (result instanceof Promise)
|
||||||
|
return result.then(finalizer).catch(reportStepError);
|
||||||
finalizer();
|
finalizer();
|
||||||
return result;
|
return result;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
||||||
|
|
@ -480,7 +480,7 @@ test('should report custom expect steps', async ({ runInlineTest }) => {
|
||||||
'reporter.ts': stepHierarchyReporter,
|
'reporter.ts': stepHierarchyReporter,
|
||||||
'playwright.config.ts': `
|
'playwright.config.ts': `
|
||||||
module.exports = {
|
module.exports = {
|
||||||
reporter: './reporter',
|
reporter: [['./reporter'], ['line']],
|
||||||
};
|
};
|
||||||
`,
|
`,
|
||||||
'a.test.ts': `
|
'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';
|
import { test, expect } from '@playwright/test';
|
||||||
test('pass', async ({}) => {
|
test('fail', async ({}) => {
|
||||||
expect(15).toBeWithinRange(10, 20);
|
expect(15).toBeWithinRange(10, 20);
|
||||||
|
await expect(1).toBeFailingAsync(22);
|
||||||
});
|
});
|
||||||
`
|
`
|
||||||
}, { reporter: '', workers: 1 });
|
}, { 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));
|
const objects = result.outputLines.map(line => JSON.parse(line));
|
||||||
expect(objects).toEqual([
|
expect(objects).toEqual([
|
||||||
{
|
{
|
||||||
|
|
@ -526,6 +537,16 @@ test('should report custom expect steps', async ({ runInlineTest }) => {
|
||||||
},
|
},
|
||||||
title: 'expect.toBeWithinRange',
|
title: 'expect.toBeWithinRange',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
category: 'expect',
|
||||||
|
location: {
|
||||||
|
column: 'number',
|
||||||
|
file: 'a.test.ts',
|
||||||
|
line: 'number',
|
||||||
|
},
|
||||||
|
title: 'expect.toBeFailingAsync',
|
||||||
|
error: '<error>',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
category: 'hook',
|
category: 'hook',
|
||||||
title: 'After Hooks',
|
title: 'After Hooks',
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue