Skip to content

Commit 7be6ff2

Browse files
committed
wip: demo app for docs
1 parent a6488af commit 7be6ff2

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

examples/TodoApp.spec.js

+9
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,12 @@ test('renders a todo', () => {
88
expect(wrapper.find('[data-test="todo"]').text()).toBe('Learn Vue.js 3')
99
})
1010

11+
test('creates a todo', async () => {
12+
const wrapper = mount(TodoApp)
13+
14+
wrapper.find('[data-test="new-todo"]').element.value = 'New todo'
15+
await wrapper.find('[data-test="form"]').trigger('submit')
16+
17+
expect(wrapper.findAll('[data-test="todo"]')).toHaveLength(2)
18+
})
19+

examples/TodoApp.vue

+15
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
<div v-for="todo in todos" :key="todo.id" data-test="todo">
44
{{ todo.text }}
55
</div>
6+
7+
<form data-test="form" @submit.prevent="createTodo">
8+
<input data-test="new-todo" v-model="newTodo" />
9+
</form>
610
</div>
711
</template>
812

@@ -12,6 +16,7 @@ export default {
1216
1317
data() {
1418
return {
19+
newTodo: '',
1520
todos: [
1621
{
1722
id: 1,
@@ -20,6 +25,16 @@ export default {
2025
}
2126
]
2227
}
28+
},
29+
30+
methods: {
31+
createTodo() {
32+
this.todos.push({
33+
id: 2,
34+
text: this.newTodo,
35+
completed: false
36+
})
37+
}
2338
}
2439
}
2540
</script>

0 commit comments

Comments
 (0)