How to test functions inside functional component and also using hooks values
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 25/100
- issue の種類
- ドキュメント
- 明瞭さ
- 説明が足りない
- 活発さ
- 停滞
- 技術スタック
- react, typescript
調査の方向性
例は Employee.tsx にあり、useEmployeeDetails、useEmployeeData、useCleanData を参照していますが、リポジトリのテストもソースパスも示されていません。まずこれらの hook と Employee コンポーネントを見つけ、次に更新ボタンによって引き起こされるユーザーに表示される動作を特定してください。作業範囲を決める前に、具体的な期待結果とテストの場所が必要です。
索引モデルが issue の本文から書いたものです。
説明
Hello
I will try to explain the case in the simplest way that I could:
I have a component: Employee.tsx
It has a pseudo code like this:
const Employee = () => {
const { name, status } = useEmployeeDetails();
const { updateEmployeeInfo } = useEmployeeData(();
const { clearStorage} = useCleanData();
const generalUpdate = async() => {
await updateEmployeeInfo(name, status);
clearStorage();
}
return(
<>
<span>update</update>
<button onClick={generalUpdate}></button>
</>
)
}
I am trying to write a test for 'generalUpdate' function that contains async function (updateEmployeeInfo) that is using hooks data as parameters, also I want to have a way how to access or spy on this function to be able to manipulate it and test different scenarios.
So :
1- How to access a function inside a functional component.
2- how to mock this function, especially if it is using another async function in its implementation?
Basically testing a function that is using data from hooks (or using async function inside it) and it exists inside a functional component
I hope my explanation is clear 😄
- 主要言語
- 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 が 7 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
-
bug: calling configure() without reactStrictMode resets it to undefined, silently disabling strict mode再び着手できるかも @suhailopensource が 77 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン
難易度 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 が 303 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 35/100
testing-library/react-testing-library#1430 · コメント 1 件 ·
-
`fireEvent.mouseEnter` does not forward `relatedTarget` (relatedTarget is the window instead)対応中かも @swarnim02 が 321 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 55/100
testing-library/react-testing-library の issue をすべて見る
似ている issue
-
feature request
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
メンテナーはふだん 1 日以内に返信
-
docs hacktoberfest help wanted
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
pacocartones/free-llm-api-hub#347 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
cytoscape/cytoscape.js#3536 ·
メンテナーはふだん 15 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
cuttle-cards/cuttle#1440 ·
メンテナーはふだん 1 日以内に返信
-
URL-encoded parser builds nested objects nothing reads対応中かも @Senthil455 が今日担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
Janani-bn/CivicFix#168 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信