Skip to content

Commit

Permalink
fix: set implementation if one is provided
Browse files Browse the repository at this point in the history
This allows the internals to properly store the implementation, allowing it to be acquired via `getMockImplementation`.
  • Loading branch information
Alex Miller committed Apr 27, 2023
1 parent e31e59f commit 2258fcb
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/spy/src/index.ts
Expand Up @@ -324,5 +324,9 @@ export function fn<TArgs extends any[] = any[], R = any>(
export function fn<TArgs extends any[] = any[], R = any>(
implementation?: (...args: TArgs) => R,
): Mock<TArgs, R> {
return enhanceSpy(tinyspy.internalSpyOn({ fn: implementation || (() => {}) }, 'fn')) as unknown as Mock
const enhancedSpy = enhanceSpy(tinyspy.internalSpyOn({ spy: () => {} }, 'spy'))
if (implementation)
enhancedSpy.mockImplementation(implementation)

return enhancedSpy as Mock
}

0 comments on commit 2258fcb

Please sign in to comment.