vitest-dev / vitest-dev/vitest
__mocks__ folder beside hook being ingored
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 17.1k
- Forks
- 2k
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 92
Description
Describe the bug
I want to get my useAppUrls hook to be mocked. I placed my mock in a __mocks__ folder beside the actual hook. In my test I call vi.mock(@urls/appUrls/useAppUrls). But it is not picking up the mock at all, it is just auto-mocking the return object (i.e., not seeing my file in the mocks folder).
Reproduction
If the mock is working properly, then the unit test renders link correctly (in MyComponent.test.ts) will pass.
StackBlitz Example
NOTE: I am using vite-tsconfig-paths and I believe my aliases are working properly. But the issue persists event if not using aliases, see the MyComponentNoAlias.test.ts file.
System Info
System:
OS: Windows 11 10.0.26100
CPU: (32) x64 AMD Ryzen 9 7950X 16-Core Processor
Memory: 31.97 GB / 63.14 GB
Binaries:
Node: 22.14.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD
npm: 11.2.0 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: Chromium (134.0.3124.85)
Internet Explorer: 11.0.26100.1882
But the issue exists on Stack Blitz, as well as my Linux laptop.
Used Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked StackBlitz reproduction and inspect src/urls/appUrls/mocks/useAppUrls.ts, MyComponent.test.ts, and MyComponentNoAlias.test.ts. Run the unit test named "renders link correctly" with and without the alias; done means the test passes using the beside-the-hook mock rather than only an auto-mocked return object.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript, vite
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100