Skip to content

Commit 6fc0687

Browse files
committed
feat: add test
1 parent cb67b5f commit 6fc0687

File tree

6 files changed

+71
-9
lines changed

6 files changed

+71
-9
lines changed

playground/plugins/increment.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { defineNuxtPlugin, useNuxtApp } from '#imports';
2+
3+
export default defineNuxtPlugin(() => {
4+
const { $store } = useNuxtApp();
5+
6+
if (process.server) {
7+
$store.dispatch('increment');
8+
}
9+
});

test/basic.test.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
import { describe, it, expect } from 'vitest'
2-
import { fileURLToPath } from 'node:url'
3-
import { setup, $fetch } from '@nuxt/test-utils'
1+
import { describe, it, expect } from 'vitest';
2+
import { fileURLToPath } from 'node:url';
3+
import { setup, $fetch } from '@nuxt/test-utils';
44

55
describe('ssr', async () => {
66
await setup({
77
rootDir: fileURLToPath(new URL('./fixtures/basic', import.meta.url)),
8-
})
8+
});
99

1010
it('renders the index page', async () => {
1111
// Get response to a server-rendered page with `$fetch`.
12-
const html = await $fetch('/')
13-
expect(html).toContain('<div>basic</div>')
14-
})
15-
})
12+
const html = await $fetch('/');
13+
14+
expect(html).toContain('<div>count: 0</div>');
15+
expect(html).toContain('<div>server: 1</div>');
16+
});
17+
});

test/fixtures/basic/app.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<template>
2-
<div>basic</div>
2+
<div>count: {{ $store.state.count }}</div>
3+
<div>server: {{ $store.state.server.count }}</div>
34
</template>
45

56
<script setup>
7+
import { useNuxtApp } from '#imports';
8+
9+
const { $store } = useNuxtApp();
610
</script>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { defineNuxtPlugin, useNuxtApp } from '#imports';
2+
3+
export default defineNuxtPlugin(() => {
4+
const { $store } = useNuxtApp();
5+
6+
if (process.server) {
7+
$store.dispatch('server/increment');
8+
}
9+
});

test/fixtures/basic/store/index.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export type IndexState = {
2+
count: number;
3+
};
4+
5+
export const state = () => ({
6+
count: 0,
7+
});
8+
9+
export const mutations = {
10+
increment(state: IndexState) {
11+
state.count++;
12+
},
13+
};
14+
15+
export const actions = {
16+
increment({ commit }: { commit: any }) {
17+
commit('increment');
18+
},
19+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
type CountState = {
2+
count: number;
3+
};
4+
5+
export const state = () => ({
6+
count: 0,
7+
});
8+
9+
export const mutations = {
10+
increment(state: CountState) {
11+
state.count++;
12+
},
13+
};
14+
15+
export const actions = {
16+
increment({ commit }: { commit: any }) {
17+
commit('increment');
18+
},
19+
};

0 commit comments

Comments
 (0)