From 9d03a5136665e0244ac9b8ffb1cf62076b48aa44 Mon Sep 17 00:00:00 2001 From: Younes Jaaidi Date: Thu, 11 Apr 2024 15:14:32 +0200 Subject: [PATCH] feat(ct-angular): throw an explicit error when mounting JSX --- packages/playwright-ct-angular/registerSource.mjs | 8 ++++++++ tests/components/ct-angular/tests/unsupported.spec.tsx | 6 ++++++ 2 files changed, 14 insertions(+) create mode 100644 tests/components/ct-angular/tests/unsupported.spec.tsx 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'); +});