Calling render on a component that throws, results in 4 renders
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 25/100
- issue の種類
- バグ
- 明瞭さ
- 説明が足りない
- 活発さ
- 停滞
- 技術スタック
- javascript, react, typescript
調査の方向性
リンクされている error-component.spec.tsx と error-component.tsx の再現手順から始め、指定されている React、Jest、@testing-library/react のバージョンでテストを実行します。レンダリングパスを追跡して、エラーをスローするコンポーネントが繰り返し呼び出される理由を特定します。観測されたレンダリング回数が説明され、適切なテストカバレッジによって期待される動作が確立されれば、この問題は解決です。
索引モデルが issue の本文から書いたものです。
説明
- @testing-library/react version: 14.2.2
- Testing Framework and version: jest 29.4.1
- DOM Environment: jest-environment-jsdom 29.4.1
- node: 20.11.1
- react: 18.2.0
Relevant code or config:
https://github.com/R-J-dev/example-error-render-issue/blob/main/src/test-error/error-component.tsx
error-component.tsx (just as an example, I know the return is unreachable):
export const ErrorComponent = () => {
// This logs four times, but it should log only once?
console.log('test error in component');
// When debugging this during a test, the debugger wil stop here five times. But we expect that it stops only once?
throw new Error('test error in component');
return <p>This is an error test component, which will throw an error</p>;
};
error-component.spec.tsx:
import { render } from '@testing-library/react';
import { ErrorComponent } from './error-component';
it('should throw', () => {
expect(() => render(<ErrorComponent />)).toThrow('test error in component');
});
What you did:
I was trying to test if a specific error was thrown in a component and used the render function from @testing-library/react.
What happened:
When debugging the component that is called in the render function, I found out that it seems to load 4/5 times.
Without throwing an error in the component that is being rendered, the component only loads once.
When calling the component that throws an error without the render function, the component only loads once.
Reproduction:
Reproduction repo can be found here: https://github.com/R-J-dev/example-error-render-issue/tree/main
It's a new setup created with: npx create-nx-workspace@latest (https://nx.dev/getting-started/intro)
The test: https://github.com/R-J-dev/example-error-render-issue/blob/main/src/test-error/error-component.spec.tsx
The component: https://github.com/R-J-dev/example-error-render-issue/blob/main/src/test-error/error-component.tsx
Problem description:
Not sure if this is normal behavior, but for me it's unexpected behavior and couldn't find why this is happening.
Also:
- Probably not good for test performance
- Mocking things once isn't possible, when testing if an error has thrown
Suggested solution:
It looks like that the problem is in the render function from @testing-library/react, but besides from that I have no clue yet.
- 主要言語
- JavaScript
- スター
- 19.7k
- フォーク
- 1.2k
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
testing-library/react-testing-library のほかの issue
-
fireEvent.select does not wrap its automatic native focus in act対応中かも @sergioperezcheco が 1 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
-
bug: calling configure() without reactStrictMode resets it to undefined, silently disabling strict mode再び着手できるかも @suhailopensource が 72 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 35/100
testing-library/react-testing-library#1466 · コメント 1 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 30/100
testing-library/react-testing-library#1459 · コメント 2 件 ·
-
perf: optimize container lookup with early exit再び着手できるかも @Ch-Abhinav-Chowdary が 298 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 35/100
testing-library/react-testing-library#1430 · コメント 1 件 ·
-
`fireEvent.mouseEnter` does not forward `relatedTarget` (relatedTarget is the window instead)対応中かも @swarnim02 が 315 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 55/100
testing-library/react-testing-library の issue をすべて見る
似ている issue
-
`yarn vitest:update` (documented) throws locally; local Cypress scripts target an unserved portオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
rescript-lang/rescript-lang.org#1415 ·
メンテナーはふだん 2 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
Deepak3699/Ai_Mentor#244 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
antithesishq/bombadil#361 ·
メンテナーはふだん 1 日以内に返信
-
ungroomed
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
dequelabs/axe-core#5455 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
DietrichGebert/ponytail#1072 ·
メンテナーはふだん 3 日以内に返信