Skip to content

Commit c290e34

Browse files
committed
Set up basic Vue component test
1 parent c39fccb commit c290e34

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { mount } from '@vue/test-utils';
2+
import { expect, test } from 'vitest';
3+
import TextFieldtype from '@/components/fieldtypes/TextFieldtype.vue';
4+
import TextInput from '@/components/inputs/Text.vue';
5+
6+
test('sets mode', async () => {
7+
const wrapper = mount(TextFieldtype, {
8+
props: {
9+
value: null,
10+
handle: 'name',
11+
},
12+
components: {
13+
TextInput,
14+
},
15+
});
16+
17+
const input = wrapper.find('input');
18+
expect(input.element.value).toBe('');
19+
expect(wrapper.emitted('update:value')).toBeUndefined();
20+
21+
await input.setValue('John');
22+
expect(input.element.value).toBe('John');
23+
expect(wrapper.emitted('update:value')[0]).toEqual(['John']);
24+
});

resources/js/tests/setup.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { config } from '@vue/test-utils';
2+
3+
config.global.directives = {
4+
tooltip: () => {},
5+
};
6+
7+
config.global.mocks = {
8+
__: (key) => key,
9+
};

vite.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import laravel from 'laravel-vite-plugin';
33
import vue from '@vitejs/plugin-vue';
44
import inject from '@rollup/plugin-inject';
55
import svgLoader from 'vite-svg-loader';
6+
import path from 'path';
67

78
export default defineConfig(({ mode }) => {
89
const env = loadEnv(mode, process.cwd(), '');
@@ -28,13 +29,15 @@ export default defineConfig(({ mode }) => {
2829
resolve: {
2930
alias: {
3031
vue: 'vue/dist/vue.esm-bundler.js',
32+
'@': path.resolve(__dirname, 'resources/js'),
3133
},
3234
},
3335
optimizeDeps: {
3436
include: ['vue'],
3537
},
3638
test: {
3739
environment: 'jsdom',
40+
setupFiles: 'resources/js/tests/setup.js',
3841
},
3942
};
4043
});

0 commit comments

Comments
 (0)