Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cant use utils/composables within tests #802

Closed
2 of 4 tasks
MickL opened this issue Mar 21, 2024 · 3 comments
Closed
2 of 4 tasks

Cant use utils/composables within tests #802

MickL opened this issue Mar 21, 2024 · 3 comments

Comments

@MickL
Copy link

MickL commented Mar 21, 2024

Describe the feature

Within tests utils and composables (especially from the server folder) should be available, currently they are not:

https://stackblitz.com/edit/github-krtpdn-tvzxcc?file=test%2Fsomething.spec.ts

Usecase:
I want to test server endpoints but for that I need to do some database queries. Within my application I use Drizzle for that which I wrapped in a util. I would like to reuse exactly this utils and possibly other composables.

Additional information

  • Would you be willing to help implement this feature?
  • Could this feature be implemented as a module?

Final checks

@danielroe
Copy link
Member

Currently only the client-side half of Nuxt is available within unit testing environment, which does include your composables in ~/composables and ~/utils. For support of server composables or server environment (such as database access), we can track in #531.

I note that you are using e2e tests - nothing in your Nuxt environment is exposed in an e2e environment. You would need to directly fetch from an api endpoint. You can run code within your app that tests for if (import.meta.test) if you want to run something conditionally only in a test env (it will be tree-shaken out when building).

@danielroe danielroe closed this as not planned Won't fix, can't repro, duplicate, stale Mar 21, 2024
@MickL
Copy link
Author

MickL commented Mar 21, 2024

Thanks for your answers! I am getting "somewhere" testing my server routes, if there wouldnt be this bug: #795 - So I am kinda working blind + every time I need to wait 15s for the next result.

Copy link
Member

Yeah, that's a pain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants