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

mockRestore does not restore the original implementation #3335

Closed
6 tasks done
andrew-w-ross opened this issue May 9, 2023 · 1 comment · Fixed by #3341
Closed
6 tasks done

mockRestore does not restore the original implementation #3335

andrew-w-ross opened this issue May 9, 2023 · 1 comment · Fixed by #3341

Comments

@andrew-w-ross
Copy link

Describe the bug

According to the docs mockRestore should restore the original implementation.

I would expect the following test to pass:

import { expect, test, vi } from 'vitest';

const testFn = vi.fn(() => true);

test('.mockRestore() should restore initial implementation', () => {
  expect(testFn()).toBe(true);

  testFn.mockReturnValue(false);
  expect(testFn()).toBe(false);

  testFn.mockRestore();
  expect(testFn()).toBe(true);
});

I get the following error on stack blitz:

AssertionError: expected undefined to be true // Object.is equality

It seems that instead of restoring the implementation it's wiped completely.
I'd expect that from mockReset not mockRestore.

Reproduction

StackBlitz Reproduction

System Info

System:
    OS: macOS 13.3.1
    CPU: (8) x64 Apple M1
    Memory: 25.78 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.12.1 - ~/.nvm/versions/node/v18.12.1/bin/node
    Yarn: 3.3.0 - ~/.nvm/versions/node/v18.12.1/bin/yarn
    npm: 8.19.2 - ~/.nvm/versions/node/v18.12.1/bin/npm
  Browsers:
    Chrome: 113.0.5672.92
    Safari: 16.4
  npmPackages:
    vitest: ^0.31.0 => 0.31.0

Used Package Manager

yarn

Validations

@stackblitz
Copy link

stackblitz bot commented May 9, 2023

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@github-actions github-actions bot locked and limited conversation to collaborators Jun 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants