Skip to content

getMockImplementation only returns permanent implementation, not onceImplementation #7030

@chaptergy

Description

@chaptergy

Describe the bug

The getMockImplementation() method only returns permanent implementations, not implementations only added once. So the return value of getMockImplementation() can be different, than the implementation being called.
To me, it would make sense, that this method always returns the implementation, that will be called on the next call.

Reproduction

const fn = vi.fn();
fn.mockReturnValueOnce('foo');
const mockImpl = fn.getMockImplementation(); // This returns undefined

System Info

Binaries:
    Node: 20.15.1
    npm: 10.9.0
  npmPackages:
    vite: ^5.4.6 => 5.4.6
    vitest: ^2.1.1 => 2.1.1

Used Package Manager

npm

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    p3-minor-bugAn edge case that only affects very specific usage (priority)

    Type

    No type

    Projects

    Status

    Approved

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions