Skip to content

Feature: a way replace inner function in spy mocking  #6234

Open
@CyanChanges

Description

@CyanChanges

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

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions