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

Mocking es modules in browser mode #7242

Open
6 tasks done
alexprudhomme opened this issue Jan 13, 2025 · 2 comments
Open
6 tasks done

Mocking es modules in browser mode #7242

alexprudhomme opened this issue Jan 13, 2025 · 2 comments

Comments

@alexprudhomme
Copy link

alexprudhomme commented Jan 13, 2025

Describe the bug

Is module mocking properly implemented in browser mode ? I can't seem to make it work. I saw this PR and supposedly it is suppose to work.
I am mocking my package like so :

vi.mock('uuid', () => ({
  v4: 'mocked-id',
}));

What am I doing wrong ? I added a stackblitz for a more complete example.

Thanks

Reproduction

https://stackblitz.com/edit/vitest-dev-vitest-mzcobmhk?file=test%2Fbasic.test.ts

System Info

System:
    OS: macOS 15.2
    CPU: (12) arm64 Apple M3 Pro
    Memory: 1.83 GB / 36.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.12.0 - ~/.nvm/versions/node/v22.12.0/bin/node
    npm: 11.0.0 - ~/.nvm/versions/node/v22.12.0/bin/npm
  Browsers:
    Chrome: 131.0.6778.265
    Safari: 18.2
  npmPackages:
    vite: 5.4.11 => 5.4.11

Used Package Manager

npm

Validations

@hi-ogawa
Copy link
Contributor

Your stackblitz is working after downloading locally. It's possible that browser mode might break on stackblitz.

Can you provide more details if it breaks on your local?

Copy link

Hello @alexprudhomme. Please provide a minimal reproduction using a GitHub repository or StackBlitz (you can also use examples). Issues marked with needs reproduction will be closed if they have no activity within 3 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants