-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Mock module does not work when imported in vue sfc files in typescript #1484
Comments
I had a similar issue and the comment below solved my problem. At the top of my test file, I now have:
|
Hello @OneFourFree, thank you for the response. I did already test your solution before I added this issue (I should have mention that in my description). In my case this approach does not help. The UPDATEI also added an example test on stackblitz. You get an error there that |
As I was investigating this issue a bit further I found, that other libraries can be mocked for instance like I also found, that when creating a file that has |
The next thing I tried was to directly mock the selected file inside the // inside component
import Plyr from 'plyr'; and use mocking like // vitest requests the module version of the plyr and if
// the correct file is mocked, the mocking will work.
vi.mock('plyr/dist/plyr.min.mjs', () => {
// ...
}) This seems to be only related to the |
There is a bug/inconsistency in Vite (vitejs/vite#8659), and because of that we resolved paths differently, when processing This change should fix that on Vitest side: #1506 |
@sheremet-va, today I tried the |
Yeah, the fix would only work if you were doing |
Should be fixed by #1919 |
it works for me! thank you! |
Describe the bug
When importing the library
plyr
inside a Vue 3 SFC and mock it inside a test file, it will not be mocked. Instead the actual library is used inside the vue file.Reproduction
Considering having a component as follows
within the test the plyr library is mocked:
When running the test, the actual Plyr class will be logged instead of the mocked library.
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: