Recommend pretty-format library provided by jest
還沒有人認領這個 Issue。
- 主要語言
- JavaScript
- 星號
- 11.8k
- 分支
- 7.9k
- 平均合併
- 1 天 11 小時
- 30 天內合併 PR
- 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 ... */
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
開啟測試配方文件中的 Snapshot Testing 區段,將其中目前對 pretty package 的推薦與 Jest 的 pretty-format package 進行比較。更新推薦和範例以使用提議的 package,然後驗證範例仍與 Jest snapshot testing 保持一致,且頁面不再推薦 pretty。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- javascript, react
- 領域
- documentation
- Issue 類型
- 文件
- 難度
- 1/5
- 預估耗時
- 1 小時以內
- 活躍度
- 停滯
- 描述清晰度
- 描述清楚
- 新手友好度
- 45/100