how to test nuxt plugins #33490
DarlanPrado
started this conversation in
Sharing
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I created a Nuxt module, nuxt-yup (https://www.npmjs.com/package/nuxt-yup), and I wanted to test it.
This module allows accessing Yup using it either as a plugin ($yup) or as a composable (useYup).
I wanted to test its actual behavior directly. I saw some approaches using mocks, but what I wanted to validate is whether it behaves as expected according to Yup.
I couldn’t find a way to do this, so I created my own approach using fixtures as a base.
I created an app.vue like this:
And to test it, I used the following:
This was the only way I could test it directly, because my whole logic is mounted inside $yup (plugin) and the composable only fetches the plugin from useNuxtApp and returns it.
This is the same approach used by modules like NuxtUI.
I’d like to open a discussion about this and better understand how this is usually done and whether I followed the right path, because it feels a bit heavy to spin up a full Nuxt app just to run this kind of test.
An important point is that I’m targeting a Nuxt module, because that’s the scenario I’m working on, but I believe the approach would be similar if testing this inside a Nuxt application.
Beta Was this translation helpful? Give feedback.
All reactions