Skip to content

Commit 8b4bf21

Browse files
committed
Run format
1 parent dc177eb commit 8b4bf21

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

src/utils/testing/misc.ts

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ export function processTestOptions(rawOptions: TestOptions): Exclude<TestOptions
2020
/**
2121
* Utility type for removing the `this` parameter from a function's type
2222
*/
23-
type RemoveThis<T extends (this: any, ...args: any) => any> =
24-
T extends (this: any, ...args: infer U) => any
23+
type RemoveThis<T extends (this: any, ...args: any) => any> = T extends (
24+
this: any,
25+
...args: infer U
26+
) => any
2527
? U
2628
: Parameters<T>
2729

@@ -34,27 +36,38 @@ interface FuncWithSkipAndOnly<T extends (...args: any[]) => any> {
3436
/**
3537
* Refers to the three `describe` operations
3638
*/
37-
export type DescribeFunctions = typeof describe | typeof describe['only'] | typeof describe['skip'];
39+
export type DescribeFunctions =
40+
| typeof describe
41+
| (typeof describe)['only']
42+
| (typeof describe)['skip']
3843

3944
/**
4045
* Refers to the three `test` operations
4146
*/
42-
export type TestFunctions = typeof test | typeof test['only'] | typeof test['skip'];
47+
export type TestFunctions = typeof test | (typeof test)['only'] | (typeof test)['skip']
4348

4449
/**
4550
* For functions that are designed to wrap around a `describe` or `test` block. Adds the `.only` and `.skip`
4651
* properties to them. The wrapped functions should use the `this` object to access the `test` or `describe` function
4752
* they are supposed to call.
4853
*/
49-
export function wrapWithSkipAndOnly<T extends (this: DescribeFunctions, ...args: any[]) => any>(type: 'describe', f: T): FuncWithSkipAndOnly<T>
50-
export function wrapWithSkipAndOnly<T extends (this: TestFunctions, ...args: any[]) => any>(type: 'test', f: T): FuncWithSkipAndOnly<T>
51-
export function wrapWithSkipAndOnly<T extends (this: TestFunctions | DescribeFunctions, ...args: any[]) => any>(type: 'test' | 'describe', f: T) {
54+
export function wrapWithSkipAndOnly<T extends (this: DescribeFunctions, ...args: any[]) => any>(
55+
type: 'describe',
56+
f: T
57+
): FuncWithSkipAndOnly<T>
58+
export function wrapWithSkipAndOnly<T extends (this: TestFunctions, ...args: any[]) => any>(
59+
type: 'test',
60+
f: T
61+
): FuncWithSkipAndOnly<T>
62+
export function wrapWithSkipAndOnly<
63+
T extends (this: TestFunctions | DescribeFunctions, ...args: any[]) => any
64+
>(type: 'test' | 'describe', f: T) {
5265
function func(...args: Parameters<T>): ReturnType<T> {
5366
return f.call(type === 'test' ? test : describe, ...args)
5467
}
5568

5669
func.skip = (...args: Parameters<T>) => {
57-
return f.call((type === 'test' ? test : describe).skip, ...args)
70+
return f.call((type === 'test' ? test : describe).skip, ...args)
5871
}
5972

6073
func.only = (...args: Parameters<T>) => {
@@ -75,13 +88,9 @@ export function assertTruthy(cond: boolean): asserts cond {
7588
* Convenience wrapper for testing multiple cases with the same
7689
* test function
7790
*/
78-
export const testMultipleCases = wrapWithSkipAndOnly('test', function <T extends Array<any>>(
79-
this: TestFunctions,
80-
cases: [string, ...T][],
81-
tester: (args: T, i: number) => void | Promise<void>,
82-
includeIndex?: boolean,
83-
timeout?: number
84-
) {
91+
export const testMultipleCases = wrapWithSkipAndOnly('test', function <
92+
T extends Array<any>
93+
>(this: TestFunctions, cases: [string, ...T][], tester: (args: T, i: number) => void | Promise<void>, includeIndex?: boolean, timeout?: number) {
8594
const withIndex = cases.map(([desc, ...c], i) => {
8695
const newDesc = includeIndex ? `${i + 1}. ${desc}` : desc
8796
return [newDesc, i, ...c] as [string, number, ...T]
@@ -132,7 +141,7 @@ function testWithChaptersInternal<T extends Promise<void> | void>(
132141
/**
133142
* @inheritDoc testWithChaptersInternal
134143
*/
135-
export const testWithChapters = wrapWithSkipAndOnly('test', testWithChaptersInternal);
144+
export const testWithChapters = wrapWithSkipAndOnly('test', testWithChaptersInternal)
136145

137146
/**
138147
* Asserts that the provided result is a `Finished`

0 commit comments

Comments
 (0)