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

test: add example fixture with @nuxt/content #631

Merged
merged 9 commits into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions examples/content/app.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<template>
<div>Index page</div>
<div>title: {{ posts[0].title }}</div>
</template>

<script setup lang="ts">
definePageMeta({
value: 'set in index'
})
const posts = await queryContent('/').limit(1).find()
</script>
9 changes: 9 additions & 0 deletions examples/content/content/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Nuxt Content

This page corresponds to the `/` route of your website. You can delete it or create another file in the `content/` directory.

Try to navigate to [/about](/about). These 2 pages are rendered by the `pages/[...slug].vue` component.

---

Look at the [Content documentation](https://content.nuxtjs.org/) to learn more.
4 changes: 4 additions & 0 deletions examples/content/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
modules: ['@nuxt/content']
})
18 changes: 18 additions & 0 deletions examples/content/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"private": true,
"type": "module",
"scripts": {
"build": "nuxt build",
"dev": "nuxt dev",
"dev:prepare": "nuxt prepare",
"generate": "nuxt generate",
"test": "vitest",
"preview": "nuxt preview"
},
"devDependencies": {
"@nuxt/content": "^2.9.0",
"@nuxt/test-utils": "latest",
"nuxt": "^3.8.2",
"vitest": "1.0.1"
}
}
23 changes: 23 additions & 0 deletions examples/content/tests/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { describe, expect, it } from 'vitest'
import { mockNuxtImport, mountSuspended } from '@nuxt/test-utils/runtime'

import App from '~/app.vue'

// Example usage: queryContent('/').limit(1).find()
mockNuxtImport('queryContent', () => (_id: string) => ({
limit: (_limit: number) => ({
find: () => [{
title: 'My page'
}]
})
}))

describe('test utils', () => {
it('can mount components within nuxt suspense', async () => {
const component = await mountSuspended(App)
expect(component.html()).toMatchInlineSnapshot(`
"<div>Index page</div>
<div>title: My page</div>"
`)
})
})
4 changes: 4 additions & 0 deletions examples/content/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
// https://v3.nuxtjs.org/concepts/typescript
"extends": "./.nuxt/tsconfig.json"
}
7 changes: 7 additions & 0 deletions examples/content/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineVitestConfig } from '@nuxt/test-utils/config'

export default defineVitestConfig({
test: {
environment: 'nuxt'
},
})
Loading
Loading