denoland / denoland/std

Feature: a way replace inner function in `spy` mocking

Open
#6,234 15 comments 0 reactions 0 assignees View on GitHub
suggestion testing
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.**

In an event emitter, I want to replace the handler to throw an error, to verify if the emitter can handle error

**Describe the solution you'd like**

Like `node:test`, you can replace the mock implementation with
```ts
import { mock } from 'node:test'
mocked_fn = mock.fn()
mocked_fn.mock.mockImplementation(()=>{ /* new logic */ })
```

**Describe alternatives you've considered**

make the `fn` in `spy(fn)` a wrapper, which call an external function variable.

Contributor guide

Open the contributing guide

Research direction

No file or test is named in the issue. Locate the existing spy implementation and its tests, then compare the current API with the node:test mockImplementation example; done means a spy's inner function can be replaced so event-emitter error handling can be tested.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
testing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.