chore: throw when a Promise was passed to toMatchSnapshot (#12906)
This commit is contained in:
parent
4b877213a1
commit
d8ab76bf64
|
|
@ -243,6 +243,8 @@ export function toMatchSnapshot(
|
||||||
const testInfo = currentTestInfo();
|
const testInfo = currentTestInfo();
|
||||||
if (!testInfo)
|
if (!testInfo)
|
||||||
throw new Error(`toMatchSnapshot() must be called during the test`);
|
throw new Error(`toMatchSnapshot() must be called during the test`);
|
||||||
|
if (received instanceof Promise)
|
||||||
|
throw new Error('An unresolved Promise was passed to toMatchSnapshot(), make sure to resolve it by adding await to it.');
|
||||||
const helper = new SnapshotHelper(
|
const helper = new SnapshotHelper(
|
||||||
testInfo, testInfo.snapshotPath.bind(testInfo), determineFileExtension(received),
|
testInfo, testInfo.snapshotPath.bind(testInfo), determineFileExtension(received),
|
||||||
testInfo.project.expect?.toMatchSnapshot || {},
|
testInfo.project.expect?.toMatchSnapshot || {},
|
||||||
|
|
|
||||||
|
|
@ -922,3 +922,17 @@ test('should allow comparing text with text without file extension', async ({ ru
|
||||||
});
|
});
|
||||||
expect(result.exitCode).toBe(0);
|
expect(result.exitCode).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should throw if a Promise was passed to toMatchSnapshot', async ({ runInlineTest }) => {
|
||||||
|
const result = await runInlineTest({
|
||||||
|
...files,
|
||||||
|
'a.spec.js': `
|
||||||
|
const { test } = require('./helper');
|
||||||
|
test('is a test', ({}) => {
|
||||||
|
expect(() => expect(new Promise(() => {})).toMatchSnapshot('foobar')).toThrow(/An unresolved Promise was passed to toMatchSnapshot\\(\\), make sure to resolve it by adding await to it./);
|
||||||
|
});
|
||||||
|
`
|
||||||
|
});
|
||||||
|
expect(result.exitCode).toBe(0);
|
||||||
|
expect(result.passed).toBe(1);
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue