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?

bun + Jest で ReferenceError: document is not defined エラーが発生する場合

Posted at

目的

  • パッケージマネージャーにnpmではなくBunを使っている
  • Jestのrender関数を使ってReactDOMやJSX(TSX)コードのテストを実行したい
  • テストを実行すると ReferenceError: document is not defined エラーが発生する

原因

  • Jestの設定(デフォルトでjest.config.js)に testEnvironment: 'jsdom' を設定する必要がある
  • bun test コマンドではbunにビルトインされたjestが使用されるため、jest.config.jsが使用されず、エラーが解消されない
  • bunを使っており、tsxで書かれたコードをjestでテストする場合は、 bun test ではなく bun run test コマンドを使う必要がある
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?