Skip to content

Commit d7258d0

Browse files
committed
test: add tests
1 parent 4cda455 commit d7258d0

File tree

7 files changed

+84
-0
lines changed

7 files changed

+84
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"devDependencies": {
1818
"@antfu/eslint-config": "^0.39.4",
1919
"@antfu/ni": "^0.21.3",
20+
"@nuxt/test-utils": "^3.5.2",
2021
"@types/node": "^18.16.16",
2122
"bumpp": "^9.1.0",
2223
"conventional-changelog-cli": "^2.2.2",

pnpm-lock.yaml

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/todos/app.vue

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<script setup lang="ts">
2+
import { useQuery } from "@tanstack/vue-query"
3+
4+
const { data, suspense } = useQuery({
5+
queryKey: ["todos"],
6+
queryFn: () => $fetch("/api/todos")
7+
})
8+
9+
onServerPrefetch(async () => {
10+
await suspense()
11+
})
12+
</script>
13+
14+
<template>
15+
<pre>
16+
{{ data }}
17+
</pre>
18+
</template>

test/fixtures/todos/nuxt.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default defineNuxtConfig({
2+
modules: ["../../../packages/vue-query-nuxt/src/module.ts"]
3+
})

test/fixtures/todos/package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "basic-fixture",
3+
"private": true,
4+
"dependencies": {
5+
"@tanstack/vue-query": "latest",
6+
"nuxt": "latest"
7+
}
8+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default defineEventHandler(() => {
2+
return [{ id: 1, todo: "Hello" }, { id: 2, todo: "World" }]
3+
})

test/todos.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { fileURLToPath } from "node:url"
2+
import { describe, expect, it } from "vitest"
3+
import { $fetch, setup } from "@nuxt/test-utils"
4+
5+
describe("vue-query", async () => {
6+
await setup({
7+
rootDir: fileURLToPath(new URL("./fixtures/todos", import.meta.url))
8+
})
9+
10+
it("renders the todos", async () => {
11+
// Get response to a server-rendered page with `$fetch`.
12+
const html = await $fetch("/")
13+
expect(html).toContain("Hello")
14+
expect(html).toContain("World")
15+
})
16+
})

0 commit comments

Comments
 (0)