Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

test: add failing test for stubbed global provide#1314

Merged
danielroe merged 4 commits intonuxt:mainnuxt/test-utils:mainfrom
paulmelero:stubbing-global-providepaulmelero/test-utils:stubbing-global-provideCopy head branch name to clipboard
Feb 23, 2026
Merged

test: add failing test for stubbed global provide#1314
danielroe merged 4 commits intonuxt:mainnuxt/test-utils:mainfrom
paulmelero:stubbing-global-providepaulmelero/test-utils:stubbing-global-provideCopy head branch name to clipboard

Conversation

@paulmelero
Copy link
Copy Markdown
Contributor

@paulmelero paulmelero commented Jun 3, 2025

Caution

This PR should only serve as a reproduction for an issue I encountered with the API, but it's not fixing the issue and should not be merged as-is.

I think this is a reproduction for the case reported in #750, #1206, and #1102 (or some of them).

The main question this PR should answer is: How are we supposed to stub the value of a globally provided value?

In my experience, I could make it work by passing a provide property directly to the renderWithNuxt method (forcing the types), but it is inconsistent with the API used by tools like Vue Test Utils.

Failing test

https://github.com/nuxt/test-utils/actions/runs/15411633006/job/43364731048?pr=1314

Screensots

image

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Jun 3, 2025

Open in StackBlitz

npm i https://pkg.pr.new/@nuxt/test-utils@1314

commit: 053b665

@paulmelero paulmelero marked this pull request as ready for review June 24, 2025 20:32
@paulmelero paulmelero requested a review from danielroe as a code owner June 24, 2025 20:32
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jan 26, 2026

📝 Walkthrough

Walkthrough

A new test case "can stub injected values" was added to examples/app-vitest-full/tests/nuxt/injected-value-component.spec.ts. The test mounts the component with a provided value for VUE_INJECTED_VALUE (a literal string) and asserts the component's rendered output includes that stubbed value.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The description is directly related to the changeset, explaining the purpose of the test case and the issue it reproduces, with clear context about why the PR should not be merged.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title accurately describes the main change: a new test case for stubbing a globally provided value, which aligns with the added test in the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@examples/app-vitest-full/tests/nuxt/injected-value-component.spec.ts`:
- Around line 31-39: The test is stubbing the wrong provide key: it uses
VUE_INJECTED_VALUE (the injected string) instead of the injection token
CUSTOM_VUE_PLUGIN_SYMBOL that InjectedValueComponent actually injects; update
the mountSuspended call to provide the stub under the CUSTOM_VUE_PLUGIN_SYMBOL
key (not VUE_INJECTED_VALUE) so the component receives the stubbed value when
injected.

Comment thread examples/app-vitest-full/tests/nuxt/injected-value-component.spec.ts Outdated
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
examples/app-vitest-full/tests/nuxt/injected-value-component.spec.ts (1)

31-40: Correct symbol key — it.fails will need to flip when the underlying issue is fixed.

The previous concern about using VUE_INJECTED_VALUE as the provide key instead of the injection token has been resolved; CUSTOM_VUE_PLUGIN_SYMBOL is correct here since the component injects by that symbol.

One thing to keep in mind: it.fails inverts the assertion — if mountSuspended is ever fixed to properly forward global.provide overrides, the test body will start passing and it.fails will itself cause the suite to fail. When the fix lands, this should be converted to a plain it(...).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@examples/app-vitest-full/tests/nuxt/injected-value-component.spec.ts` around
lines 31 - 40, The test currently uses it.fails which inverts the assertion and
was intended as a temporary guard until mountSuspended correctly forwards
global.provide overrides; when that underlying bug is fixed, change the test
from it.fails(...) to a normal it(...) so the assertion for
InjectedValueComponent (which mounts via mountSuspended and provides
CUSTOM_VUE_PLUGIN_SYMBOL) runs as a regular passing test checking that
component.text() contains the stubbed value; locate the test referencing
mountSuspended, InjectedValueComponent, and CUSTOM_VUE_PLUGIN_SYMBOL and swap
it.fails to it.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@examples/app-vitest-full/tests/nuxt/injected-value-component.spec.ts`:
- Around line 31-40: The test currently uses it.fails which inverts the
assertion and was intended as a temporary guard until mountSuspended correctly
forwards global.provide overrides; when that underlying bug is fixed, change the
test from it.fails(...) to a normal it(...) so the assertion for
InjectedValueComponent (which mounts via mountSuspended and provides
CUSTOM_VUE_PLUGIN_SYMBOL) runs as a regular passing test checking that
component.text() contains the stubbed value; locate the test referencing
mountSuspended, InjectedValueComponent, and CUSTOM_VUE_PLUGIN_SYMBOL and swap
it.fails to it.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ec84a3a and 053b665.

📒 Files selected for processing (1)
  • examples/app-vitest-full/tests/nuxt/injected-value-component.spec.ts

@danielroe danielroe changed the title test: [Do not merge] Example of failing test with stubbed global provide test: add failing test for stubbed global provide Feb 23, 2026
@danielroe danielroe merged commit f77b92c into nuxt:main Feb 23, 2026
8 checks passed
@github-actions github-actions Bot mentioned this pull request Feb 23, 2026
@github-actions github-actions Bot mentioned this pull request Apr 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.