nuxt / nuxt/test-utils

Fail to mock a Nested Component with mockComponent

Open
#708 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

pending triage
Dominant language
TypeScript
Stars
437
Forks
120
Avg merge
22h 52m
Merged PRs (30d)
23

Description

Environment
  • Operating System: Linux
  • Node Version: v18.18.0
  • Nuxt Version: 3.9.1
  • CLI Version: 3.10.0
  • Nitro Version: 2.8.1
  • Package Manager: npm@10.2.3
  • Builder: -
  • User Config: devtools
  • Runtime Modules: -
  • Build Modules: -
Reproduction

https://stackblitz.com/edit/nuxt-starter-ashrbf?file=test%2Fmock.test.ts

Describe the bug

When I try to use the mockComponent helper in a new nuxt project, the test can't mock a nested component properly.

I tried the method to mock another similar components, but in this case doesn't work.

Additional context

It seams to be related if the components are in a subfolder inside the components folder.
If the components are in the component folder, it works.

It will be great to have an example with several test inside the same test suite, to explain how to manage unstubbing between tests.

Logs

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked StackBlitz reproduction and test/mock.test.ts, then trace how mockComponent resolves components in subfolders. Confirm the behavior with a focused test for a nested component and ensure the test suite's unstubbing behavior is covered if that remains in scope.

Written by the indexing model from the issue text.

Assessment

Tech stack
nuxtjs, typescript
Domain
frontend, testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.