feat(ct-angular): throw an explicit error when mounting JSX

This commit is contained in:
Younes Jaaidi 2024-04-11 15:14:32 +02:00
parent 89804adcf4
commit 9d03a51366
No known key found for this signature in database
GPG key ID: 3126C5717BDF3241
2 changed files with 14 additions and 0 deletions

View file

@ -40,6 +40,8 @@ getTestBed().initTestEnvironment(
); );
window.playwrightMount = async (component, rootElement, hooksConfig) => { window.playwrightMount = async (component, rootElement, hooksConfig) => {
__pwAssertIsNotJsx(component);
for (const hook of window.__pw_hooks_before_mount || []) for (const hook of window.__pw_hooks_before_mount || [])
await hook({ hooksConfig, TestBed }); await hook({ hooksConfig, TestBed });
@ -69,6 +71,8 @@ window.playwrightUnmount = async rootElement => {
* @param {{type: import('@angular/core').Type<unknown>} & import('./index').MountOptions | {type: string} & import('./index').MountTemplateOptions} component * @param {{type: import('@angular/core').Type<unknown>} & import('./index').MountOptions | {type: string} & import('./index').MountTemplateOptions} component
*/ */
window.playwrightUpdate = async (rootElement, component) => { window.playwrightUpdate = async (rootElement, component) => {
__pwAssertIsNotJsx(component);
const fixture = __pwFixtureRegistry.get(rootElement.id); const fixture = __pwFixtureRegistry.get(rootElement.id);
if (!fixture) if (!fixture)
throw new Error('Component was not mounted'); throw new Error('Component was not mounted');
@ -165,6 +169,10 @@ function __pwUpdateEvents(fixture, events = {}) {
__pwOutputSubscriptionRegistry.set(fixture, outputSubscriptionRecord); __pwOutputSubscriptionRegistry.set(fixture, outputSubscriptionRecord);
} }
function __pwAssertIsNotJsx(component) {
if (component.__pw_type === 'jsx')
throw new Error('JSX mount notation is not supported');
}
/** /**
* @param {ComponentInfo} component * @param {ComponentInfo} component

View file

@ -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(<h1/> as any)).rejects.toThrow('JSX mount notation is not supported');
});