Skip to content

Vue injection warning during unit test #2481

@MelvinFrohike

Description

@MelvinFrohike

Reproduction

https://play.pinia.vuejs.org/#eNqNVMFu2zAM/RXBlzhoIrXo1kORFNmGHroBW7EWO/ni2EyqVJY0iU5TBPn3UVLiJM3Q7WSLenwkH0Wus0/W8mUL2XU28pWTFpkHbC1TpZ6Piwx9kd0UWjbWOGRr1np4QOOAbdjMmYb1uKhMqxEcR98rdKEroz2RRNC4w+f9Qo9EikB8dEBorCoR6MTYaNoiGs0mlZLVM8WN/lyfnVH4O105aEBT/HUi5pptNiORnIhgJDq2bJClZIdNafnCG02lrUOMYntBFV2zaAk2K7Usg6XInhCtvxaCiF55tAdlFp4bNxfpDL4ZTp158VTvgogGO5oJIUUNSzRG+WFp5TFlVWvC16Dk0nENKLRtxInP5Ip/5BdCyamgQELqGlbHYchjWEPzP+w76OScX3zgV+KMKIssEG0KvSGZ0FOrZnL+RqTKNFYqcD8sSmrlkVilUubla7Sha6FLq3qC6vkv9oVfpUzvHZBkSzgoBUs3B0zXtw/fYUX/3WVj6lYR+p3Ln+CNakOOCfa51TWlfYCL2d7Fnks9f/S3KwTtd0WFRKMaER+l/fJO6ft0L/nlgYr7108SdmNSw0zqN5MSXxCNSAeSegEVDpiDWQeiLOIUwSqC0jB1Qzc+JM57cRZ6A5b32fgmpZocNCGJNT+nqdvZUjSof5WqDUzpnPfSl+r9Bq89wgePWaujiUASiX2rQiAyCrgy8+AnkWIf0cZwJEz4JNf072ilOE0l09ySbP0D3byF6kS8sCemMGCkQlRI4l4gieDxUMZ/raQOSFuENsQjudNzuA/d6FwmsTm0ReJd7MAui7y3ZTsWmgok8WIub+xRqZNQQYrdbSor3+9Grvscze3vtlTbnpGM9CWlNn8AsYfl1g==

Steps to reproduce the bug

When using injection in a setup store, executing tests results in a warning:
[Vue warn]: inject() can only be used inside setup() or functional components.

It seems to me that this warning does not occur when using the store in the actual application. It only appears during unit tests.

Expected behavior

No warning on the console

Actual behavior

A warning appears on the console: [Vue warn]: inject() can only be used inside setup() or functional components.

Additional information

I'm using Vitest.

I i understand the docs[1] correctly, the above way should be correct.

Extra question: How can I provide a value during unit tests?

[1] https://pinia.vuejs.org/core-concepts/#Setup-Stores

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions