簡體   English   中英

React / Jest 從單個組件而不是全部獲得覆蓋 - 當前方法無效

[英]React / Jest get coverage from a single component not all - current approach not working

我已經嘗試過這個答案來覆蓋單個組件,但它不起作用。 測試只針對該組件運行但沒有覆蓋?

是否需要在任何地方進行其他配置?

我努力了:

npm test src/components/component1/my-component.test.tsx --coverage --collectCoverageFrom=src/components/component1/my-component.test.tsx

我做錯了什么嗎?

collectCoverageFrom 將 glob 模式作為參數,因此您需要使用“”調整該路徑字符串。

我已成功運行此命令,其中包含一個文件的代碼覆蓋率

node_modules/.bin/jest ComponentTest.test.ts --coverage --collectCoverageFrom="path/Component.tsx"

也可能是您從 package.json 運行的“測試”cmd 掩蓋了額外的 arguments,嘗試直接從模塊調用 jest 以查看是否是這種情況。

這對我有用,來自 windows cmd 的 create-react-app:

npx react-scripts test src/components/common/__test__/Dropdown.test.tsx --coverage --collectCoverageFrom=src/components/common/Dropdown.tsx

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM