test: add failing test for stubbed global provide#1314
test: add failing test for stubbed global provide#1314danielroe merged 4 commits intonuxt:mainnuxt/test-utils:mainfrom paulmelero:stubbing-global-providepaulmelero/test-utils:stubbing-global-provideCopy head branch name to clipboard
Conversation
commit: |
📝 WalkthroughWalkthroughA new test case "can stub injected values" was added to Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
examples/app-vitest-full/tests/nuxt/injected-value-component.spec.ts (1)
31-40: Correct symbol key —it.failswill need to flip when the underlying issue is fixed.The previous concern about using
VUE_INJECTED_VALUEas the provide key instead of the injection token has been resolved;CUSTOM_VUE_PLUGIN_SYMBOLis correct here since the component injects by that symbol.One thing to keep in mind:
it.failsinverts the assertion — ifmountSuspendedis ever fixed to properly forwardglobal.provideoverrides, the test body will start passing andit.failswill itself cause the suite to fail. When the fix lands, this should be converted to a plainit(...).🤖 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.
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
provideproperty directly to therenderWithNuxtmethod (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