Jest で debug 結果を最後まで表示する方法

Jest で debug 結果を最後まで表示する方法

Jest でレンダー結果のHTMLソースがすべて表示されない事象を解消する方法を残しておく。

Jest でエラーが発生した際、原因調査をしたいが、以下のように、レンダー結果のHTMLソースが「…」が出力されて、最後まで表示されないことがある。

Unable to find an element with the text: ログイン. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible.

    Ignored nodes: comments, script, style
    <body>
      <div>
        <div>
          <div>
            <div
    ...

これを解消するために、出力上限を上げることで解消できたので、残しておく。

解消方法

DEBUG_PRINT_LIMIT=10000 (数値は上限にしたい値を指定)を先頭に指定して、npm run test を実行する。

DEBUG_PRINT_LIMIT=10000 npm run test

参考リンク

Debugging | Testing Library
https://testing-library.com/docs/dom-testing-library/api-debugging/#automatic-logging

Web技術カテゴリの最新記事