@std/expect: Align `fn` function signature with Jest's `fn` type
- Dominant language
- TypeScript
- Stars
- 3.6k
- Forks
- 681
- PR merge metrics
- No merged PRs in 30d
Description
**Is your feature request related to a problem? Please describe.**
The current `fn` signature in the Deno std library is:
```typescript
function fn(...stubs: Function[]): Function
```
This lacks type safety and flexibility compared to Jest's `fn`:
```typescript
fn(implementation?: T): Mock;
```
See https://github.com/jestjs/jest/blob/main/packages/jest-mock/src/index.ts#L1082
It makes mocking less intuitive and harder to work with in a type-safe way.
**Describe the solution you'd like**
Update the `fn` function signature to match [Jest's API](https://github.com/jestjs/jest/blob/main/packages/jest-mock/src/index.ts#L1082) for better type inference and usability:
```typescript
fn(implementation?: T): Mock;
```
**Describe alternatives you've considered**
- Keeping the current implementation: This is simpler but sacrifices type safety and consistency with Jest.
- Writing custom wrappers: This adds unnecessary complexity and redundancy for users.
---
I would be happy to contribute this change myself and submit a pull request to update the implementation and associated documentation.
Contributor guide
Assessment
This issue has not been assessed yet.