test.vue
1<template> 2 <form action="/" method="post" @submit.prevent="onSubmit" ref="form"> 3 ・・・・省略・・・・ 4 <button type="submit">submit</button> 5 </form> 6</template> 7 8export default { 9 methods: { 10 onSubmit() { 11 this.$nextTick(() => { 12 this.$refs.form.submit(); 13 }); 14 } 15 } 16}
このようなVueコンポーネントがあるとします。
'@vue/test-utils + Jest'
でonSubmit
メソッドをテストしようと思ったのですが、
$refs.formのsubmitイベントが発火した
というテストの書き方がわかりません。
test.js
1import { shallowMount } from '@vue/test-utils'; 2import Test from 'test.vue'; 3 4describe('onSubmit', () => { 5 test('formのsubmitイベントが発火すること', () => { 6 const wrapper = shallowMount(Test); 7 wrapper.vm.onSubmit(); 8 wrapper.vm.$nextTick(() => { 9 // ???? 10 }); 11 }); 12});
どなたかご教示のほどよろしくお願いします。
あなたの回答
tips
プレビュー