question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using nuxt/content in test file without Nuxt instance

See original GitHub issue

Environment


  • Operating System: Darwin
  • Node Version: v17.9.1
  • Nuxt Version: 3.0.0-rc.4
  • Package Manager: yarn@1.22.17
  • Builder: vite
  • User Config: modules, experimental, components, colorMode
  • Runtime Modules: @nuxtjs/tailwindcss@5.1.3, @nuxt/content@2.0.1, @vueuse/nuxt@8.9.1, @pinia/nuxt@0.1.9, @nuxtjs/color-mode@3.1.4
  • Build Modules: -

Reproduction

i want replace this method with nuxt/content find() https://github.com/double-slash-podcast/website/blob/efd97318601f47a4379509780c8ddfcce76bd03b/__tests__/guid-episodes.test.ts#L42

Describe the bug

I can’t use nuxt/content in my test file. When i import content, it’s mendatory to init content with all options and one instance of nuxt app. But i haven’t nuxt app in my test. My question is : it’s possible to use nuxt/content outiside nuxt app ?

Additional context

import Content from '@nuxt/content'

const content  = Content({...lot of options}, nuxt instance);

Logs

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ipatatecommented, Jul 14, 2022

yeah thanks, it’s better. It’s difficult to find the good params for query but it works. 👍🏼 https://github.com/double-slash-podcast/website/blob/7ce57b088ece8cb1dc9ae14319765dc4d9433a12/__tests__/guid-episodes.test.ts#L44

1reaction
farnabazcommented, Jul 14, 2022

Ok since you have the server, you need to use $fetch function from test utils and call the query API.

import { $fetch } from '@nuxt/test-utils'

...

test('...', async () => {
  const list = await $fetch('/api/_content/query?_params={}')

})
Read more comments on GitHub >

github_iconTop Results From Across the Web

Fetching content - Nuxt Content
Learn how to fetch your static content with $content in your Nuxt.js project. ... $content instance, meaning that you can access it anywhere...
Read more >
support for unit testing in a nuxt environment #2465 - GitHub
Describe the feature Unit testing (e.g. [parts of ]composables or server functions) doesn't require a full built of nuxt.
Read more >
Component testing in Nuxt.js with Jest - LogRocket Blog
In this article, we'll learn how to set up a game store application with Nuxt.js and test its components. To follow along with...
Read more >
@nuxt/content examples - CodeSandbox
Learn how to use @nuxt/content by viewing and forking example apps that make use of @nuxt/content on CodeSandbox. ... Nuxt Content + TailwindCSS...
Read more >
How To Easily Create a Blog With Nuxt Content - Telerik
The Nuxt Content module acts as a Git-based headless CMS. You can create blog posts in the form of markdown files inside the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found