diff --git a/examples/TodoApp.spec.js b/examples/TodoApp.spec.js deleted file mode 100644 index 029bab4a8..000000000 --- a/examples/TodoApp.spec.js +++ /dev/null @@ -1,32 +0,0 @@ -/** - * This is the example app used in the documentation. - * If you want to run it, you will need to build the final bundle with - * yarn build. Then you can run this with `yarn test examples` - */ -import { mount } from '../dist/vue-test-utils.cjs.js' -import { test, expect } from 'vitest' - -import TodoApp from './TodoApp.vue' - -test('renders a todo', () => { - const wrapper = mount(TodoApp) - - expect(wrapper.find('[data-test="todo"]').text()).toBe('Learn Vue.js 3') -}) - -test('creates a todo', async () => { - const wrapper = mount(TodoApp) - - wrapper.find('[data-test="new-todo"]').element.value = 'New todo' - await wrapper.find('[data-test="form"]').trigger('submit') - - expect(wrapper.findAll('[data-test="todo"]')).toHaveLength(2) -}) - -test('completes a todo', async () => { - const wrapper = mount(TodoApp) - - await wrapper.find('[data-test="todo-checkbox"]').setChecked() - - expect(wrapper.find('[data-test="todo"]').classes()).toContain('completed') -}) diff --git a/examples/TodoApp.spec.ts b/examples/TodoApp.spec.ts new file mode 100644 index 000000000..80feffcee --- /dev/null +++ b/examples/TodoApp.spec.ts @@ -0,0 +1,38 @@ +/** + * This is the example app used in the documentation. + * If you want to run it, you will need to build the final bundle with + * pnpm build. Then you can run this with `pnpm test examples` + */ +import { mount } from '../dist/vue-test-utils.cjs.js' +import { expect, describe, it } from 'vitest' + +import TodoApp from './TodoApp.vue' + +describe('Todo App', () => { + it('renders a todo', () => { + const wrapper = mount(TodoApp) + + expect(wrapper.findAll('[data-test="todo"]')).toHaveLength(1) + expect(wrapper.find('[data-test="todo"]').text()).toBe('Learn Vue.js 3') + }) + + it('creates a todo', async () => { + const wrapper = mount(TodoApp) + + await wrapper.find('[data-test="new-todo"]').setValue('New todo') + await wrapper.find('[data-test="form"]').trigger('submit') + expect(wrapper.findAll('[data-test="todo"]')).toHaveLength(2) + }) + + it('completes a todo', async () => { + const wrapper = mount(TodoApp) + + expect(wrapper.find('[data-test="todo"]').classes()).not.toContain( + 'completed' + ) + + await wrapper.find('[data-test="todo-checkbox"]').setChecked() + + expect(wrapper.find('[data-test="todo"]').classes()).toContain('completed') + }) +}) diff --git a/examples/TodoApp.vue b/examples/TodoApp.vue index e5d50d731..4a22ae72b 100644 --- a/examples/TodoApp.vue +++ b/examples/TodoApp.vue @@ -4,7 +4,7 @@ v-for="todo in todos" :key="todo.id" data-test="todo" - :class="[todo.completed ? 'completed' : '']" + :class="{ completed: todo.completed }" > {{ todo.text }} -