Skip to content

Commit

Permalink
Add another test to show toBeCallableWith can handle up to 5 overloads
Browse files Browse the repository at this point in the history
  • Loading branch information
aryaemami59 committed Mar 22, 2024
1 parent 85a3733 commit b708fce
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -751,3 +751,38 @@ test('`toBeCallableWith()` can handle overloads', () => {

expectTypeOf(dispatch).toBeCallableWith({type: 'INCREMENT'})
})

test('`toBeCallableWith()` can handle up to 5 overloads', () => {
function performAction(): void
// eslint-disable-next-line no-redeclare, @typescript-eslint/no-shadow
function performAction(a: string): number
// eslint-disable-next-line no-redeclare, @typescript-eslint/no-shadow
function performAction(a: number): boolean
// eslint-disable-next-line no-redeclare, @typescript-eslint/no-shadow
function performAction(a: boolean): string
// eslint-disable-next-line no-redeclare, @typescript-eslint/no-shadow
function performAction(a: string, b: string, c: string): {a: string; b: string; c: string}
// Implementation signature, not exposed as part of the overloads
// eslint-disable-next-line no-redeclare, @typescript-eslint/no-shadow
function performAction(a?: string | number | boolean, b?: string | number | boolean, _c?: string): any {
// Dummy implementation that just demonstrates the concept
if (typeof a === 'string' && b === undefined) {
return a.length // Example operation for single string argument
} else if (typeof a === 'number' && b === undefined) {
return !!(a % 2) // Example for single number argument
} else if (typeof a === 'boolean' && b === undefined) {
return a ? 'true' : 'false' // Example for single boolean argument
} else if (typeof a === 'string' && typeof b === 'string') {
return [a, b] // Example for two string arguments
}
// Additional logic to handle other overloads
// For simplicity, not all cases are fully implemented here
return null
}

expectTypeOf(performAction).toBeCallableWith()
expectTypeOf(performAction).toBeCallableWith('')
expectTypeOf(performAction).toBeCallableWith(0)
expectTypeOf(performAction).toBeCallableWith(true)
expectTypeOf(performAction).toBeCallableWith('', '', '')
})

0 comments on commit b708fce

Please sign in to comment.