https://juejin.cn/post/7199865975277649978#heading-37
https://jestjs.io/zh-Hans/docs/snapshot-testing
基礎(chǔ)語法
describe:
將多個相關(guān)的測試組合在一起的塊
test:
將運(yùn)行測試的方法,別名是it
expect:
斷言
skip:
跳過describe.skip/test.skip
cleanup:
測試用例結(jié)束后,確保所有的狀態(tài)能回歸到最初狀態(tài)
import renderer from 'react-test-renderer';
waitFor
1、快照測試
2、dom 結(jié)構(gòu)測試
3、事件測試
4、function測試
5、異步測試
6、模擬屬性和方法的返回結(jié)果
7、Drag
8、test.only
* [在項目中遇到的一些問題]
[1、執(zhí)行 pnpm test 報錯]
[2、ts-jest和jest版本未對應(yīng)]
[3、toBeInTheDocument、toHaveClass等報錯]
[9、Echarts 單元測試 canvas 報錯]
[10、引入了第三方的組件CodeMirrorEditor寫單測報錯]
[11、Route && Link]
[6、由于單測的運(yùn)行環(huán)境問題,當(dāng)遇到某些方法沒有的時候嘗試mock下]
[7、多個單測文件缺失某一個方法,可以采用如下配置]
[4、Cannot find namespace 'NodeJS’]
[5、module 'tslib' cannot be found]
[8、The error below may be caused by using the wrong test environment;
Consider using the "jsdom" test environment]
Component Data:組件靜態(tài)數(shù)據(jù)
Component Props:組件動態(tài)數(shù)據(jù)
User Interaction:用戶交互,例如單擊
LifeCycle Methods:生命周期邏輯
Store:組件狀態(tài)值
Route Params:路由參數(shù)
輸出的dom
外部調(diào)用的函數(shù)
對子組件的改變