-
Notifications
You must be signed in to change notification settings - Fork 0
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
Vitest mock issue when running tests #44
Comments
Okay, so i found out, this happens, when test uses class which uses any kind of
which works in the app, but in the test its problematic, but i dont know why. Trying string instead of token works for me:
|
Thanks for reporting this issue. Let's see if we can reproduce it. Can you clone this StackBlitz and try to reproduce it in there? Alternatively, you can share me a reproduction in a Github repository. |
Sorry, i was little bit busy, i will try to do some more debugging later :). |
Let me know, I am motivated to help you out here. ;) |
Hello, sorry for the huge delay again, i am back at the project, I did some more testing and it seems to work if i follow the "auto-binding", if i have everything related "manually" binded to the container, it throws the mentioned error with vitest. |
No problem! Hm, only thing I can imagine is some kind of cyclic dependency or something. Still interested in a small example, if you have the time, it would be very helpful to prevent this issue for others. 😎 |
I can actually provide my "playground" project: https://github.com/octotravel/validator/tree/feat/monorepo. I still cant get tokens to work, for example in: https://github.com/octotravel/validator/blob/feat/monorepo/backend/src/common/database/Database.ts There is the following line currently commented out:
With current state when i run
It works again. Since this migration from tsyringe is a long term PR its possible that i am just overlooking something in the project or in your docs :). |
I haven't tested it, but my gut feeling it has to do with cyclic dependencies. What if you move the injection token |
I will try that and let you know, but if that's the case, it would be good to do some extra logging by default or enable some kind of "debug/verbose" mode on the container. Update: moving the token and/or bind to its own file doesnt help in this case. |
I will try to dive deeper in your case later this week! |
Thank you! No worries, its not some priority on my side anyway |
Hello there,
i migrated the project from tsyringe, and it works perfectly fine.
When running vitest following occurs when i try to mock a dependency, which is normally injected in the constructor:
Mentioned part of the code in test:
Can this be due to some invalid or missing setting, like
target
ofES2022
or something like that?The text was updated successfully, but these errors were encountered: