better error message

This commit is contained in:
Max Schmitt 2024-09-10 11:04:56 +02:00
parent 7b040a075d
commit 1bdb9d57cd
2 changed files with 5 additions and 4 deletions

View file

@ -68,8 +68,9 @@ export function transformObject(value: any, mapping: (v: any) => { result: any }
} }
if (value?.__pw_type === 'jsx' && typeof value.type === 'function') { if (value?.__pw_type === 'jsx' && typeof value.type === 'function') {
throw new Error([ throw new Error([
'JSX component was not able to get resolved.', `Component "${value.type.name}" cannot be mounted.`,
'Make sure to define components outside of your test file.' `Most likely, this component is defined in the test file. Create a test story instead.`,
`For more information, see https://playwright.dev/docs/test-components#test-stories.`,
].join('\n')); ].join('\n'));
} }
const result2: any = {}; const result2: any = {};

View file

@ -38,11 +38,11 @@ function MyInlineComponent({ value }: { value: string }) {
} }
test('render inline component with an error', async ({ mount }) => { test('render inline component with an error', async ({ mount }) => {
await expect(mount(<MyInlineComponent value="Max" />)).rejects.toThrow('JSX component was not able to get resolved'); await expect(mount(<MyInlineComponent value="Max" />)).rejects.toThrow('Component "MyInlineComponent" cannot be mounted.');
}); });
test('render inline component with an error if its nested', async ({ mount }) => { test('render inline component with an error if its nested', async ({ mount }) => {
await expect(mount(<DefaultChildren> await expect(mount(<DefaultChildren>
<MyInlineComponent value="Max" /> <MyInlineComponent value="Max" />
</DefaultChildren>)).rejects.toThrow('JSX component was not able to get resolved'); </DefaultChildren>)).rejects.toThrow('Component "MyInlineComponent" cannot be mounted.');
}); });