mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
@@ -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(
|
||||
|
||||
@@ -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>;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user