File tree Expand file tree Collapse file tree 3 files changed +61
-59
lines changed Expand file tree Collapse file tree 3 files changed +61
-59
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ /**
2+ * This is the example app used in the documentation.
3+ * If you want to run it, you will need to build the final bundle with
4+ * pnpm build. Then you can run this with `pnpm test examples`
5+ */
6+ import { mount } from '../dist/vue-test-utils.cjs.js'
7+ import { expect , describe , it } from 'vitest'
8+
9+ import TodoApp from './TodoApp.vue'
10+
11+ describe ( 'Todo App' , ( ) => {
12+ it ( 'renders a todo' , ( ) => {
13+ const wrapper = mount ( TodoApp )
14+
15+ expect ( wrapper . findAll ( '[data-test="todo"]' ) ) . toHaveLength ( 1 )
16+ expect ( wrapper . find ( '[data-test="todo"]' ) . text ( ) ) . toBe ( 'Learn Vue.js 3' )
17+ } )
18+
19+ it ( 'creates a todo' , async ( ) => {
20+ const wrapper = mount ( TodoApp )
21+
22+ await wrapper . find ( '[data-test="new-todo"]' ) . setValue ( 'New todo' )
23+ await wrapper . find ( '[data-test="form"]' ) . trigger ( 'submit' )
24+ expect ( wrapper . findAll ( '[data-test="todo"]' ) ) . toHaveLength ( 2 )
25+ } )
26+
27+ it ( 'completes a todo' , async ( ) => {
28+ const wrapper = mount ( TodoApp )
29+
30+ expect ( wrapper . find ( '[data-test="todo"]' ) . classes ( ) ) . not . toContain (
31+ 'completed'
32+ )
33+
34+ await wrapper . find ( '[data-test="todo-checkbox"]' ) . setChecked ( )
35+
36+ expect ( wrapper . find ( '[data-test="todo"]' ) . classes ( ) ) . toContain ( 'completed' )
37+ } )
38+ } )
Original file line number Diff line number Diff line change 44 v-for =" todo in todos"
55 :key =" todo.id"
66 data-test =" todo"
7- :class =" [todo.completed ? ' completed' : ''] "
7+ :class =" { completed: todo.completed } "
88 >
99 {{ todo.text }}
1010 <input
2020 </div >
2121</template >
2222
23- <script lang="ts">
24- import { defineComponent } from ' vue'
23+ <script setup lang="ts">
24+ import { ref } from ' vue'
2525
26- export default defineComponent ({
27- name: ' TodoApp' ,
26+ interface TODO {
27+ id: number
28+ text: string
29+ completed: boolean
30+ }
2831
29- data() {
30- return {
31- newTodo: ' ' ,
32- todos: [
33- {
34- id: 1 ,
35- text: ' Learn Vue.js 3' ,
36- completed: false
37- }
38- ]
39- }
40- },
41-
42- methods: {
43- createTodo() {
44- this .todos .push ({
45- id: 2 ,
46- text: this .newTodo ,
47- completed: false
48- })
49- }
32+ const newTodo = ref <string >(' ' )
33+ const todos = ref <TODO []>([
34+ {
35+ id: 1 ,
36+ text: ' Learn Vue.js 3' ,
37+ completed: false
5038 }
51- })
39+ ])
40+
41+ const createTodo = () => {
42+ todos .value .push ({
43+ id: 2 ,
44+ text: newTodo .value ,
45+ completed: false
46+ })
47+ }
5248 </script >
You can’t perform that action at this time.
0 commit comments