Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e2295c6

Browse files
feat: add stronger types (#413)
1 parent a5ad0c8 commit e2295c6

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

‎projects/testing-library/src/lib/models.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
import { Type, DebugElement, EventEmitter, Signal, InputSignalWithTransform } from '@angular/core';
1+
import {
2+
Type,
3+
DebugElement,
4+
ModuleWithProviders,
5+
EventEmitter,
6+
EnvironmentProviders,
7+
Provider,
8+
Signal,
9+
InputSignalWithTransform,
10+
} from '@angular/core';
211
import { ComponentFixture, DeferBlockBehavior, DeferBlockState, TestBed } from '@angular/core/testing';
312
import { Routes } from '@angular/router';
413
import { BoundFunction, Queries, queries, Config as dtlConfig, PrettyDOMOptions } from '@testing-library/dom';
@@ -153,7 +162,7 @@ export interface RenderComponentOptions<ComponentType, Q extends Queries = typeo
153162
* declarations: [ CustomerDetailComponent, ButtonComponent ]
154163
* })
155164
*/
156-
declarations?: any[];
165+
declarations?: (Type<unknown>|unknown[])[];
157166
/**
158167
* @description
159168
* A collection of providers needed to render the component via Dependency Injection, for example, injectable services or tokens.
@@ -174,7 +183,7 @@ export interface RenderComponentOptions<ComponentType, Q extends Queries = typeo
174183
* ]
175184
* })
176185
*/
177-
providers?: any[];
186+
providers?: (Provider|EnvironmentProviders)[];
178187
/**
179188
* @description
180189
* A collection of imports needed to render the component, for example, shared modules.
@@ -192,7 +201,7 @@ export interface RenderComponentOptions<ComponentType, Q extends Queries = typeo
192201
* ]
193202
* })
194203
*/
195-
imports?: any[];
204+
imports?: (Type<unknown>|ModuleWithProviders<unknown>)[];
196205
/**
197206
* @description
198207
* A collection of schemas needed to render the component.
@@ -314,7 +323,7 @@ export interface RenderComponentOptions<ComponentType, Q extends Queries = typeo
314323
* ]
315324
* })
316325
*/
317-
componentProviders?: any[];
326+
componentProviders?: Provider[];
318327
/**
319328
* @description
320329
* Collection of child component specified providers to override with
@@ -348,7 +357,7 @@ export interface RenderComponentOptions<ComponentType, Q extends Queries = typeo
348357
* ]
349358
* })
350359
*/
351-
componentImports?: (Type<any> | any[])[];
360+
componentImports?: (Type<unknown> | unknown[])[];
352361
/**
353362
* @description
354363
* Queries to bind. Overrides the default set from DOM Testing Library unless merged.
@@ -462,7 +471,7 @@ export interface RenderComponentOptions<ComponentType, Q extends Queries = typeo
462471

463472
export interface ComponentOverride<T> {
464473
component: Type<T>;
465-
providers: any[];
474+
providers: Provider[];
466475
}
467476

468477
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
@@ -496,7 +505,7 @@ export interface Config extends Pick<RenderComponentOptions<any>, 'excludeCompon
496505
/**
497506
* Imports that are added to the imports
498507
*/
499-
defaultImports: any[];
508+
defaultImports?: (Type<unknown>|ModuleWithProviders<unknown>)[];
500509
/**
501510
* Set to `true` to use zoneless change detection.
502511
* This automatically adds `provideZonelessChangeDetection` to the default imports.

‎projects/testing-library/src/lib/testing-library.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
OnChanges,
77
OutputRef,
88
OutputRefSubscription,
9+
Provider,
910
SimpleChange,
1011
SimpleChanges,
1112
Type,
@@ -436,7 +437,7 @@ function overrideComponentImports<SutType>(sut: Type<SutType> | string, imports:
436437
function overrideChildComponentProviders(componentOverrides: ComponentOverride<any>[]) {
437438
if (componentOverrides) {
438439
for (const { component, providers } of componentOverrides) {
439-
TestBed.overrideComponent(component, { set: { providers } });
440+
TestBed.overrideComponent(component, { set: { providers: providersasProvider[] } });
440441
}
441442
}
442443
}
@@ -499,7 +500,7 @@ function addAutoDeclarations<SutType>(
499500
wrapper,
500501
}: Pick<RenderTemplateOptions<any>, 'declarations' | 'excludeComponentDeclaration' | 'wrapper'>,
501502
) {
502-
const nonStandaloneDeclarations = declarations?.filter((d) => !isStandalone(d));
503+
const nonStandaloneDeclarations = declarations.filter((d) => !isStandalone(dasType<any>));
503504
if (typeof sut === 'string') {
504505
if (wrapper && isStandalone(wrapper)) {
505506
return nonStandaloneDeclarations;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /