From f59d4d60bd6a5e3d10e29e3e55e4ae1f9482d4cb Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Thu, 9 Dec 2021 20:51:51 +0800 Subject: [PATCH] feat: use vitest for testing --- README.md | 3 + auto-imports.d.ts | 16 + components.d.ts | 1 + package.json | 9 +- pnpm-lock.yaml | 1978 ++++++++++++++++++++- src/components/Counter.vue | 19 + test/__snapshots__/component.test.ts.snap | 3 + test/basic.test.ts | 7 + test/component.test.ts | 22 + vite.config.ts | 5 + 10 files changed, 2055 insertions(+), 8 deletions(-) create mode 100644 src/components/Counter.vue create mode 100644 test/__snapshots__/component.test.ts.snap create mode 100644 test/basic.test.ts create mode 100644 test/component.test.ts diff --git a/README.md b/README.md index 3997f15..764ee00 100644 --- a/README.md +++ b/README.md @@ -26,10 +26,13 @@ - 🔥 Use the [new ` + + diff --git a/test/__snapshots__/component.test.ts.snap b/test/__snapshots__/component.test.ts.snap new file mode 100644 index 0000000..aa529f1 --- /dev/null +++ b/test/__snapshots__/component.test.ts.snap @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Counter.vue > should render 1`] = `"
10
"`; diff --git a/test/basic.test.ts b/test/basic.test.ts new file mode 100644 index 0000000..542fa32 --- /dev/null +++ b/test/basic.test.ts @@ -0,0 +1,7 @@ +import { describe, it, expect } from 'vitest' + +describe('Hi', () => { + it('should works', () => { + expect(1 + 1).toEqual(2) + }) +}) diff --git a/test/component.test.ts b/test/component.test.ts new file mode 100644 index 0000000..ba014df --- /dev/null +++ b/test/component.test.ts @@ -0,0 +1,22 @@ +import { mount } from '@vue/test-utils' +import { describe, it, expect } from 'vitest' +import Counter from '../src/components/Counter.vue' + +describe('Counter.vue', () => { + it('should render', () => { + const wrapper = mount(Counter, { props: { initial: 10 } }) + expect(wrapper.text()).toContain('10') + expect(wrapper.html()).toMatchSnapshot() + }) + + it('should be interactive', async() => { + const wrapper = mount(Counter, { props: { initial: 0 } }) + expect(wrapper.text()).toContain('0') + + expect(wrapper.find('.inc').exists()).toBe(true) + + await wrapper.get('button').trigger('click') + + expect(wrapper.text()).toContain('1') + }) +}) diff --git a/vite.config.ts b/vite.config.ts index eeca3df..e93384a 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -25,6 +25,7 @@ export default defineConfig({ 'vue', 'vue-router', '@vueuse/core', + 'vitest', ], dts: true, }), @@ -60,4 +61,8 @@ export default defineConfig({ 'vue-demi', ], }, + + test: { + dom: 'jsdom', + }, })