reactjs / reactjs/react.dev

Recommend pretty-format library provided by jest

オープン
#2,929 コメント 5 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
JavaScript
スター
11.8k
フォーク
7.9k
平均マージ
1日 11時間
マージ済み PR(30日)
11

説明

I was going through the testing recipes and noticed that the documentation recommends a npm module for pretty printing HTML for snapshot: https://reactjs.org/docs/testing-recipes.html#snapshot-testing.

In this example, we render a component and format the rendered HTML with the pretty package, before saving it as an inline snapshot...

The package is this: https://www.npmjs.com/package/pretty. There is another, imo stronger candidate to replace this package, which is pretty-format. Why would this be better? Its part of jest and the example code in the documentation is already using jest. Therefor it would be better to recommend a dependency from a source that the reader is already more likely to be using other dependencies from (which in this case is jest).

You can pretty print HTML with pretty-format like so:

import prettyFormat from 'pretty-format';

const pretty = (dom: HTMLElement): string => {
  return prettyFormat(
    dom,
    {
      plugins: [ prettyFormat.plugins.DOMElement ]
    }
  )
}

...

expect(
  pretty(container)
).toMatchInlineSnapshot(); /* ... gets filled automatically by jest ... */

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

テストレシピのドキュメントにある「Snapshot Testing」セクションを開き、現在の pretty package の推奨を Jest の pretty-format package と比較してください。推奨と例を更新して提案された package を使用するようにし、その後、例が Jest の snapshot testing と引き続き整合していること、およびページで pretty が推奨されなくなっていることを確認してください。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript, react
領域
documentation
issue の種類
ドキュメント
難易度
1/5
見積もり時間
1時間未満
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。