はじめに
document.activeElementのテストをJestで書いていた時に沼にハマったので備忘録として残す
モック方法
mountでtemplateを定義した後、attachToでdocument.bodyを定義することでdocument.activeElementを使う事が出来るようになる
component.spec.js
const wrapper = ('component', () =>
mount({
template: `<div>
<input type='text' />
<input type='text' />
<input type='text' />
</div>`,
},
{
attachTo: document.body,
})
参考
https://qiita.com/ykhirao/items/8e8a9547a693c677813c
https://vue-test-utils.vuejs.org/ja/api/options.html#attachtodocument