Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getMockImplementation only returns permanent implementation, not onceImplementation #7030

Open
6 tasks done
chaptergy opened this issue Dec 5, 2024 · 0 comments · May be fixed by #7033
Open
6 tasks done

getMockImplementation only returns permanent implementation, not onceImplementation #7030

chaptergy opened this issue Dec 5, 2024 · 0 comments · May be fixed by #7033
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@chaptergy
Copy link

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

@chaptergy chaptergy changed the title getMockImplementation only returns permanent implementaion, not onceImplementation getMockImplementation only returns permanent implementation, not onceImplementation Dec 5, 2024
@sheremet-va sheremet-va added p3-minor-bug An edge case that only affects very specific usage (priority) and removed pending triage labels Dec 5, 2024
@sheremet-va sheremet-va moved this to Approved in Team Board Dec 5, 2024
@chaptergy chaptergy linked a pull request Dec 5, 2024 that will close this issue
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
Status: Approved
Development

Successfully merging a pull request may close this issue.

2 participants