You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've observed a strange behaviour with whitespace characters (tab versus spaces). I can't say for sure it's related to vi.mock() but I was using vi.mock() when I noticed the glitch.
When a tab character precedes vi.mock(), the implementation fails.
Or paste the following code (with NO INDENTATION) into one of your own projects:
import{expect,test,vi}from'vitest'import{joinasjoinPath}from'node:path'consthelloWorld=()=>{returnjoinPath('hello','world')}test('Are you mocking me?',()=>{// note there are NO indents in this file// except the next line// test pass with spaces, test fails with tabvi.mock('node:path',()=>{return{join: vi.fn().mockReturnValue('goodbye world')}})expect(helloWorld()).toBe('goodbye world')})
Add a couple of spaces at the line beginning with vi.mock(
This is indeed a bug, but I would recommend you keep vi.mock always in the global scope, since it's moved there by Vitest anyway. It is not executed in a test block, so if you have many vi.mock calls, only one of them is actually executed, which might be confusing.
Describe the bug
I've observed a strange behaviour with whitespace characters (tab versus spaces). I can't say for sure it's related to vi.mock() but I was using vi.mock() when I noticed the glitch.
When a tab character precedes vi.mock(), the implementation fails.
Reproduction
See this file: https://github.com/DavidSabine/vitest-issue/blob/main/__tests__/weird.test.mjs
Or paste the following code (with NO INDENTATION) into one of your own projects:
vi.mock(
I reproduce it in this few seconds of screenshare: https://youtu.be/R8EgVU2TrB4
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: