feat(ct-angular): throw an explicit error when mounting JSX
This commit is contained in:
parent
89804adcf4
commit
9d03a51366
|
|
@ -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<unknown>} & 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
|
||||
|
|
|
|||
6
tests/components/ct-angular/tests/unsupported.spec.tsx
Normal file
6
tests/components/ct-angular/tests/unsupported.spec.tsx
Normal 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');
|
||||
});
|
||||
Loading…
Reference in a new issue