1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[Jest]document.activeElementを使えるようにする方法

Last updated at Posted at 2020-12-15

はじめに

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

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?