fix(ct-angular): resolve Angular imports/providers usages

This commit is contained in:
Younes Jaaidi 2024-03-27 22:47:06 +01:00
parent 89b885a273
commit fcc1635185
No known key found for this signature in database
GPG key ID: 3126C5717BDF3241
2 changed files with 12 additions and 8 deletions

View file

@ -147,11 +147,15 @@ function collectClassMountUsages(node: T.Node): Set<string> {
const names = new Set<string>();
traverse(node, {
enter: p => {
// Treat calls to mount as component usages.
// e.g. mount(MyComponent, ...)
if (t.isCallExpression(p.node) && t.isIdentifier(p.node.callee) && p.node.callee.name === 'mount' && t.isIdentifier(p.node.arguments[0]))
names.add(p.node.arguments[0].name);
// Treat calls to mount and all identifiers in arguments as component usages.
// e.g. mount(MyComponent, { imports: [OtherComponent], providers: [Token]})
if (t.isCallExpression(p.node) && t.isIdentifier(p.node.callee) && p.node.callee.name === 'mount') {
p.traverse({
Identifier: p => {
names.add(p.node.name);
}
});
}
}
});
return names;

View file

@ -4,7 +4,7 @@ import { expect, test } from "@playwright/experimental-ct-angular"
test('render a template', async ({ mount }) => {
const component = await mount('<h1>{{ 1 + 1 }}</h1>');
await expect(component.getByRole('heading')).toContainText('2');
await expect(component).toHaveText('2');
})
test('render a template with child components', async ({ mount }) => {
@ -38,7 +38,7 @@ test('render a template with outputs', async ({ mount }) => {
}
});
component.getByRole('button').click();
await component.getByRole('button').click();
await expect(async () => {expect(_message).toBe('hello')}).toPass();
})
})