diff --git a/packages/playwright-ct-angular/registerSource.mjs b/packages/playwright-ct-angular/registerSource.mjs index 5fcb88384a..f6884eebee 100644 --- a/packages/playwright-ct-angular/registerSource.mjs +++ b/packages/playwright-ct-angular/registerSource.mjs @@ -40,6 +40,8 @@ getTestBed().initTestEnvironment( ); window.playwrightMount = async (component, rootElement, hooksConfig) => { + __pwAssertIsNotJsx(component); + for (const hook of window.__pw_hooks_before_mount || []) await hook({ hooksConfig, TestBed }); @@ -69,6 +71,8 @@ window.playwrightUnmount = async rootElement => { * @param {{type: import('@angular/core').Type} & import('./index').MountOptions | {type: string} & import('./index').MountTemplateOptions} component */ window.playwrightUpdate = async (rootElement, component) => { + __pwAssertIsNotJsx(component); + const fixture = __pwFixtureRegistry.get(rootElement.id); if (!fixture) throw new Error('Component was not mounted'); @@ -165,6 +169,10 @@ function __pwUpdateEvents(fixture, events = {}) { __pwOutputSubscriptionRegistry.set(fixture, outputSubscriptionRecord); } +function __pwAssertIsNotJsx(component) { + if (component.__pw_type === 'jsx') + throw new Error('JSX mount notation is not supported'); +} /** * @param {ComponentInfo} component diff --git a/tests/components/ct-angular/tests/unsupported.spec.tsx b/tests/components/ct-angular/tests/unsupported.spec.tsx new file mode 100644 index 0000000000..caebee478e --- /dev/null +++ b/tests/components/ct-angular/tests/unsupported.spec.tsx @@ -0,0 +1,6 @@ +import { expect, test } from '@playwright/experimental-ct-angular'; + +test('should throw an error when mounting JSX', async ({ mount }) => { + // @ts-ignore + await expect(mount(

as any)).rejects.toThrow('JSX mount notation is not supported'); +});