feat(ct-angular): allow setting providers
This commit is contained in:
parent
a1fee2ae9b
commit
e22b5cf85c
3
packages/playwright-ct-angular/index.d.ts
vendored
3
packages/playwright-ct-angular/index.d.ts
vendored
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
9
tests/components/ct-angular/tests/providers.spec.ts
Normal file
9
tests/components/ct-angular/tests/providers.spec.ts
Normal 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');
|
||||
});
|
||||
Loading…
Reference in a new issue