vue.js test
#jest
vue3対応のものをやらないといけないが、、
Vue.jsテストハンドブック | Vueテストハンドブック
日本語のが理解しやすいので日本語で読んで、でも、英文のがupToDateなので、そちらを参照する。
componentのrender. ok
shallowMount()は、Vue componentsがstubになるので、子供componentsを関心外における。
mount, shallowMountの引数に、 component, props, stub, datastoreなどを入れて、テストするコンポーネントを作る。
computed()は、
FooRenderer.computed.HogeValue.call(localThis ).toBe('....
といった形で、算出propertyに callで値をbindしてtestする
shallowMountをskipして、直接 importしたcomponent.computed.itscomputed.call..といける。
ユーザー入力
wrapper.find('form').trigger('submit.prevent')
shallowMount(renderer, {mocks: $http:mockHttp})
これで、$httpをmockしてる。mockHttpはもちろん自分で書く。
mockHtttpの中で、該当する?変数にassignしてsimulateすることもできる(便利かも)
Event emitter
wrapper.vm.emitEvent()すると、wrapper.emitted() で発生したEventオブジェクトが取れる
mountせずに HogeComponent.methods.emitMyEvent.call( { (e,..args) => {e[event] = [...args]}})でもok