0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

JestでscrollToが存在しないとエラー

Posted at

Chakra UI で作成した複数選択可能なドロップダウンリストを実装後にテストをしていたところ下記のエラーが発生しました。

dom.getContentEl(...)?.scrollTo is not a function

原因

内部的に使用しているscrollToが Jest のテスト環境に存在しないため、エラーになっています。

対策

scrollToに対してモックを行います。今回は各テスト前にモックしました。

beforeAll(() => {
  // Mock scrollTo to prevent TypeError
  Element.prototype.scrollTo = jest.fn();
});

おわりに

Jest は基本便利なのですが、たまにいきなりエラーを出力することがあるので難しいと感じています。

この記事が皆様のコーディングライフの助けになれば幸いです。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?