Skip to content

Add stronger types #413

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: beta
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions projects/testing-library/src/lib/models.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { Type, DebugElement, EventEmitter, Signal, InputSignalWithTransform } from '@angular/core';
import {
Type,
DebugElement,
ModuleWithProviders,
EventEmitter,
EnvironmentProviders,
Provider,
Signal,
InputSignalWithTransform,
} from '@angular/core';
import { ComponentFixture, DeferBlockBehavior, DeferBlockState, TestBed } from '@angular/core/testing';
import { Routes } from '@angular/router';
import { BoundFunction, Queries, queries, Config as dtlConfig, PrettyDOMOptions } from '@testing-library/dom';
Expand Down Expand Up @@ -153,7 +162,7 @@ export interface RenderComponentOptions<ComponentType, Q extends Queries = typeo
* declarations: [ CustomerDetailComponent, ButtonComponent ]
* })
*/
declarations?: any[];
declarations?: (Type<unknown> | unknown[])[];
/**
* @description
* A collection of providers needed to render the component via Dependency Injection, for example, injectable services or tokens.
Expand All @@ -174,7 +183,7 @@ export interface RenderComponentOptions<ComponentType, Q extends Queries = typeo
* ]
* })
*/
providers?: any[];
providers?: (Provider | EnvironmentProviders)[];
/**
* @description
* A collection of imports needed to render the component, for example, shared modules.
Expand All @@ -192,7 +201,7 @@ export interface RenderComponentOptions<ComponentType, Q extends Queries = typeo
* ]
* })
*/
imports?: any[];
imports?: (Type<unknown> | ModuleWithProviders<unknown>)[];
/**
* @description
* A collection of schemas needed to render the component.
Expand Down Expand Up @@ -314,7 +323,7 @@ export interface RenderComponentOptions<ComponentType, Q extends Queries = typeo
* ]
* })
*/
componentProviders?: any[];
componentProviders?: Provider[];
/**
* @description
* Collection of child component specified providers to override with
Expand Down Expand Up @@ -348,7 +357,7 @@ export interface RenderComponentOptions<ComponentType, Q extends Queries = typeo
* ]
* })
*/
componentImports?: (Type<any> | any[])[];
componentImports?: (Type<unknown> | unknown[])[];
/**
* @description
* Queries to bind. Overrides the default set from DOM Testing Library unless merged.
Expand Down Expand Up @@ -462,7 +471,7 @@ export interface RenderComponentOptions<ComponentType, Q extends Queries = typeo

export interface ComponentOverride<T> {
component: Type<T>;
providers: any[];
providers: Provider[];
}

// eslint-disable-next-line @typescript-eslint/no-empty-object-type
Expand Down Expand Up @@ -496,7 +505,7 @@ export interface Config extends Pick<RenderComponentOptions<any>, 'excludeCompon
/**
* Imports that are added to the imports
*/
defaultImports: any[];
defaultImports?: (Type<unknown> | ModuleWithProviders<unknown>)[];
/**
* Set to `true` to use zoneless change detection.
* This automatically adds `provideZonelessChangeDetection` to the default imports.
Expand Down
5 changes: 3 additions & 2 deletions projects/testing-library/src/lib/testing-library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
OnChanges,
OutputRef,
OutputRefSubscription,
Provider,
SimpleChange,
SimpleChanges,
Type,
Expand Down Expand Up @@ -436,7 +437,7 @@ function overrideComponentImports<SutType>(sut: Type<SutType> | string, imports:
function overrideChildComponentProviders(componentOverrides: ComponentOverride<any>[]) {
if (componentOverrides) {
for (const { component, providers } of componentOverrides) {
TestBed.overrideComponent(component, { set: { providers } });
TestBed.overrideComponent(component, { set: { providers: providers as Provider[] } });
}
}
}
Expand Down Expand Up @@ -499,7 +500,7 @@ function addAutoDeclarations<SutType>(
wrapper,
}: Pick<RenderTemplateOptions<any>, 'declarations' | 'excludeComponentDeclaration' | 'wrapper'>,
) {
const nonStandaloneDeclarations = declarations?.filter((d) => !isStandalone(d));
const nonStandaloneDeclarations = declarations.filter((d) => !isStandalone(d as Type<any>));
if (typeof sut === 'string') {
if (wrapper && isStandalone(wrapper)) {
return nonStandaloneDeclarations;
Expand Down