diff --git a/eslint.config.js b/eslint.config.js index e0670e5..45c94f3 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -14,5 +14,17 @@ export default defineConfig( 'unicorn/no-array-reverse': 'off', }, }, + { + files: ['src/types.ts'], + rules: { + '@typescript-eslint/no-explicit-any': 'off', + }, + }, + { + files: ['test/typing.test-d.ts'], + rules: { + '@typescript-eslint/no-unsafe-argument': 'off', + }, + }, globalIgnores(['**/coverage/**', '**/dist/**']), ) diff --git a/src/types.ts b/src/types.ts index 4f679d0..2e9d6dd 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,6 +1,4 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ /** Common type definitions. */ -import type { AsymmetricMatcher } from '@vitest/expect' import type { MockedClass, MockedFunction } from 'vitest' /** Any function. */ @@ -81,11 +79,6 @@ export type ConstructorImplementation< | (new (...args: ConstructorParameters) => InstanceType) | ((this: InstanceType, ...args: ConstructorParameters) => void) -/** Accept a value or an AsymmetricMatcher in an arguments array */ -export type WithMatchers = { - [K in keyof T]: AsymmetricMatcher | T[K] -} - /** A mocked function or constructor. */ export type Mock = TFunc extends AnyConstructor ? MockedClass diff --git a/src/vitest-when.ts b/src/vitest-when.ts index 0a6f549..f0230b4 100644 --- a/src/vitest-when.ts +++ b/src/vitest-when.ts @@ -10,7 +10,6 @@ import type { NormalizeMockable, ParametersOf, ReturnTypeOf, - WithMatchers, } from './types.ts' export { type Behavior, BehaviorType, type WhenOptions } from './behaviors.ts' @@ -21,9 +20,7 @@ export interface StubWrapper< TFunc extends AnyMockable, TOptions extends WhenOptions | undefined, > { - calledWith, TOptions>>( - ...args: WithMatchers - ): Stub + calledWith(...args: ArgumentsSpec, TOptions>): Stub } export interface Stub { diff --git a/test/typing.test-d.ts b/test/typing.test-d.ts index bbc94ae..56c6603 100644 --- a/test/typing.test-d.ts +++ b/test/typing.test-d.ts @@ -75,6 +75,14 @@ describe('vitest-when type signatures', () => { subject .when(multipleArgs, { ignoreExtraArgs: true }) .calledWith(expect.any(Number), expect.any(String), expect.any(Boolean)) + + subject.when(multipleArgs, { ignoreExtraArgs: true }).calledWith( + // @ts-expect-error: too many arguments + expect.anything(), + expect.anything(), + expect.anything(), + expect.anything(), + ) }) it('returns mock type for then resolve', () => { diff --git a/test/vitest-when.test.ts b/test/vitest-when.test.ts index 92e49ac..57e405a 100644 --- a/test/vitest-when.test.ts +++ b/test/vitest-when.test.ts @@ -281,7 +281,7 @@ describe('vitest-when', () => { }) it.each([ - { stubArgs: [] as unknown[], callArgs: [] as unknown[] }, + { stubArgs: [], callArgs: [] }, { stubArgs: [], callArgs: ['a'] }, { stubArgs: [], callArgs: ['a', 'b'] }, { stubArgs: ['a'], callArgs: ['a'] }, @@ -300,7 +300,7 @@ describe('vitest-when', () => { ) it.each([ - { stubArgs: ['a'] as unknown[], callArgs: ['b'] as unknown[] }, + { stubArgs: ['a'], callArgs: ['b'] }, { stubArgs: [undefined], callArgs: [] }, ])( 'does not match call $callArgs against stub $stubArgs with ignoreExtraArgs',