Chore: improve types (#78126)

* fix some types

* more type updates

* some more fixes

* more changes

* string instead of unknown

* more like original logic

* remove outdated comment

* update betterer
This commit is contained in:
Ashley Harrison
2023-11-16 12:39:12 +00:00
committed by GitHub
parent b0448b92e5
commit 2c0c51a0df
43 changed files with 135 additions and 236 deletions

View File

@@ -3,7 +3,7 @@ import { Observable, Subscription } from 'rxjs';
import { expectObservable, forceObservableCompletion } from './utils';
function tryExpectations(received: unknown[], expectations: (received: unknown[]) => void): jest.CustomMatcherResult {
function tryExpectations<T = unknown>(received: T[], expectations: (received: T[]) => void): jest.CustomMatcherResult {
try {
expectations(received);
return {
@@ -27,9 +27,9 @@ function tryExpectations(received: unknown[], expectations: (received: unknown[]
* the observable ended (or emitted error). If Observable does not complete within OBSERVABLE_TEST_TIMEOUT_IN_MS the
* test fails.
*/
export function toEmitValuesWith(
received: Observable<any>,
expectations: (actual: any[]) => void
export function toEmitValuesWith<T = unknown>(
received: Observable<T>,
expectations: (actual: T[]) => void
): Promise<jest.CustomMatcherResult> {
const failsChecks = expectObservable(received);
if (failsChecks) {
@@ -37,7 +37,7 @@ export function toEmitValuesWith(
}
return new Promise((resolve) => {
const receivedValues: any[] = [];
const receivedValues: T[] = [];
const subscription = new Subscription();
subscription.add(

View File

@@ -2,12 +2,10 @@ import { Observable } from 'rxjs';
export const OBSERVABLE_TEST_TIMEOUT_IN_MS = 1000;
export type ObservableType<T> = T extends Observable<infer V> ? V : never;
export interface ObservableMatchers<R, T = {}> extends jest.ExpectExtendMap {
toEmitValues<E = ObservableType<T>>(received: T, expected: E[]): Promise<jest.CustomMatcherResult>;
toEmitValuesWith<E = ObservableType<T>>(
received: T,
expectations: (received: E[]) => void
toEmitValues<T>(received: Observable<T>, expected: T[]): Promise<jest.CustomMatcherResult>;
toEmitValuesWith<T>(
received: Observable<T>,
expectations: (received: T[]) => void
): Promise<jest.CustomMatcherResult>;
}

View File

@@ -39,7 +39,7 @@ export function ControllerTestContext(this: any) {
$provide.value('templateSrv', self.templateSrv);
$provide.value('$element', self.$element);
$provide.value('$sanitize', self.$sanitize);
each(mocks, (value: any, key: any) => {
each(mocks, (value, key) => {
$provide.value(key, value);
});
});