You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We've encountered an issue integrating Plausible Analytics in a Nuxt 3 application, specifically during testing with vitest. Despite following documentation and trying various mocking strategies, we're unable to successfully mock useTrackPageview and related functionalities for our unit tests. This results in tests failing due to Nuxt instance availability errors or incorrect mock implementations.
Steps to Reproduce
Integrate Plausible Analytics in a Nuxt 3 application.
Implement unit testing for components or functionalities utilizing Plausible's useTrackPageview or useTrackEvent.
Attempt to mock Plausible's functionalities using Vitest.
Expected Behavior
Mocks for Plausible's useTrackPageview and useTrackEvent should correctly simulate their functionalities, allowing for successful execution of unit tests without encountering Nuxt instance availability errors.
Actual Behavior
Tests fail with errors related to Nuxt instance availability or incorrect mock implementations. Specifically, we encountered errors like [nuxt] instance unavailable when trying to mock useTrackPageview.
Tried Solutions
Mocking @nuxtjs/plausible and #app (for useNuxtApp) globally in our Vitest setup file.
Adjusting mock implementations to closely match the signatures and behaviors of Plausible's functions.
Ensuring mocks for $plausible are included as part of the object returned by useNuxtApp.
Despite these efforts, the issue persists, indicating a potential gap in documentation or support for this specific use case.
Additional Context
Guidance on correctly mocking Plausible Analytics for unit tests in a Nuxt 3 application, or any updates to the documentation or package that could help address this issue.
Thank you
The text was updated successfully, but these errors were encountered:
We've encountered an issue integrating Plausible Analytics in a Nuxt 3 application, specifically during testing with
vitest
. Despite following documentation and trying various mocking strategies, we're unable to successfully mockuseTrackPageview
and related functionalities for our unit tests. This results in tests failing due toNuxt
instance availability errors or incorrect mock implementations.Steps to Reproduce
Expected Behavior
Mocks for Plausible's
useTrackPageview
anduseTrackEvent
should correctly simulate their functionalities, allowing for successful execution of unit tests without encountering Nuxt instance availability errors.Actual Behavior
Tests fail with errors related to Nuxt instance availability or incorrect mock implementations. Specifically, we encountered errors like [nuxt] instance unavailable when trying to mock
useTrackPageview.
Tried Solutions
Despite these efforts, the issue persists, indicating a potential gap in documentation or support for this specific use case.
Additional Context
Test Result:
Request
Guidance on correctly mocking Plausible Analytics for unit tests in a Nuxt 3 application, or any updates to the documentation or package that could help address this issue.
Thank you
The text was updated successfully, but these errors were encountered: