Skip to content

Commit

Permalink
test: add example fixture with @nuxt/content (#631)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe authored Dec 9, 2023
1 parent 404af27 commit 705e2aa
Show file tree
Hide file tree
Showing 8 changed files with 1,665 additions and 293 deletions.
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

0 comments on commit 705e2aa

Please sign in to comment.