feat(ct-angular): allow setting providers

This commit is contained in:
Younes Jaaidi 2024-02-23 18:01:11 +01:00
parent a1fee2ae9b
commit e22b5cf85c
No known key found for this signature in database
GPG key ID: 3126C5717BDF3241
3 changed files with 14 additions and 3 deletions

View file

@ -25,7 +25,7 @@ import type {
} from '@playwright/test';
import type { JsonObject } from '@playwright/experimental-ct-core/types/component';
import type { InlineConfig } from 'vite';
import type { Type } from '@angular/core';
import type { Provider, Type } from '@angular/core';
export type PlaywrightTestConfig<T = {}, W = {}> = Omit<BasePlaywrightTestConfig<T, W>, 'use'> & {
use?: BasePlaywrightTestConfig<T, W>['use'] & {
@ -43,6 +43,7 @@ type ComponentEvents = Record<string, Function>;
export interface MountOptions<HooksConfig extends JsonObject, Component> {
props?: Partial<Component> | Record<string, unknown>, // TODO: filter props and handle signals
providers?: Provider[],
slots?: ComponentSlots;
on?: ComponentEvents;
hooksConfig?: HooksConfig;

View file

@ -97,9 +97,9 @@ async function __pwRenderComponent(component) {
if (__pwIsTemplate(component)) {
const templateInfo = /** @type {TemplateInfo} */(component);
componentClass = defineComponent({
imports: templateInfo.imports,
selector: 'pw-template-component',
standalone: true,
selector: 'pw-template-component',
imports: templateInfo.imports,
template: templateInfo.type,
})(class {});
} else {
@ -112,6 +112,7 @@ async function __pwRenderComponent(component) {
TestBed.configureTestingModule({
imports: [componentClass],
providers: component.providers,
});
await TestBed.compileComponents();

View file

@ -0,0 +1,9 @@
import { InjectComponent, TOKEN } from "@/components/inject.component";
import { expect, test } from "@playwright/experimental-ct-angular";
test('inject a token', async ({ mount }) => {
const component = await mount(InjectComponent, {
providers: [{ provide: TOKEN, useValue: { text: 'has been overwritten' }}]
});
await expect(component).toHaveText('has been overwritten');
});