feat(ct-angular): render simple template
This commit is contained in:
parent
d91da7b795
commit
e024fba04f
|
|
@ -59,6 +59,9 @@ window.playwrightUnmount = async rootElement => {
|
||||||
fixture.nativeElement.replaceChildren();
|
fixture.nativeElement.replaceChildren();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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) => {
|
||||||
if (component.slots)
|
if (component.slots)
|
||||||
throw new Error('Update slots is not supported yet');
|
throw new Error('Update slots is not supported yet');
|
||||||
|
|
@ -79,13 +82,18 @@ const __pwOutputSubscriptionRegistry = new WeakMap();
|
||||||
/** @type {Map<string, import('@angular/core/testing').ComponentFixture>} */
|
/** @type {Map<string, import('@angular/core/testing').ComponentFixture>} */
|
||||||
const __pwFixtureRegistry = new Map();
|
const __pwFixtureRegistry = new Map();
|
||||||
/**
|
/**
|
||||||
* @param {Component} component
|
* @param {{type: import('@angular/core').Type<unknown>} & import('./index').MountOptions | {type: string} & import('./index').MountTemplateOptions } component
|
||||||
*/
|
*/
|
||||||
async function __pwRenderComponent(component) {
|
async function __pwRenderComponent(component) {
|
||||||
const componentClass = component.type;
|
let componentClass = component.type;
|
||||||
if (!componentClass)
|
|
||||||
throw new Error(`Unregistered component: ${componentClass}. Following components are registered: ${[...__pwRegistry.keys()]}`);
|
|
||||||
|
|
||||||
|
if (typeof componentClass === 'string') {
|
||||||
|
componentClass = defineComponent({
|
||||||
|
selector: 'pw-template-component',
|
||||||
|
standalone: true,
|
||||||
|
template: componentClass
|
||||||
|
})(class {});
|
||||||
|
}
|
||||||
|
|
||||||
const componentMetadata = reflectComponentType(componentClass);
|
const componentMetadata = reflectComponentType(componentClass);
|
||||||
if (!componentMetadata?.isStandalone)
|
if (!componentMetadata?.isStandalone)
|
||||||
|
|
@ -135,8 +143,8 @@ function __pwUpdateEvents(fixture, events = {}) {
|
||||||
outputSubscriptionRecord[name]?.unsubscribe();
|
outputSubscriptionRecord[name]?.unsubscribe();
|
||||||
|
|
||||||
const subscription = fixture.debugElement.children[0].componentInstance[
|
const subscription = fixture.debugElement.children[0].componentInstance[
|
||||||
name
|
name
|
||||||
].subscribe((event) => listener(event));
|
].subscribe((/** @type {unknown} */ event) => listener(event));
|
||||||
|
|
||||||
/* Store new subscription. */
|
/* Store new subscription. */
|
||||||
outputSubscriptionRecord[name] = subscription;
|
outputSubscriptionRecord[name] = subscription;
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
import { ButtonComponent } from "@/components/button.component";
|
import { ButtonComponent } from "@/components/button.component";
|
||||||
import { expect, test } from "@playwright/experimental-ct-angular"
|
import { expect, test } from "@playwright/experimental-ct-angular"
|
||||||
|
|
||||||
test.skip('render a template', async ({ mount }) => {
|
test('render a template', async ({ mount }) => {
|
||||||
const component = await mount('<h1>Hello</h1>');
|
const component = await mount('<h1>{{ 1 + 1 }}</h1>');
|
||||||
|
|
||||||
await expect(component.getByRole('heading')).toContainText('Hello');
|
await expect(component.getByRole('heading')).toContainText('2');
|
||||||
})
|
})
|
||||||
|
|
||||||
test.skip('render a template with child components', async ({ mount }) => {
|
test.skip('render a template with child components', async ({ mount }) => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue