jest 學習筆記

  • 基礎配置

mapCoverage: false 運行報錯 須要刪除;複製代碼

rootDir: path.resolve(__dirname, '../../'), 定義根路徑複製代碼
moduleNameMapper: {
  // 支持源代碼中相同的 `@` -> `src` 別名
  '^@/(.*)$': '<rootDir>/src/$1'
},複製代碼
// 須要忽略的測試文件
testPathIgnorePatterns: [
  '<rootDir>/test/e2e',
  '<rootDir>/test/unit'
],複製代碼
transform: {
  // 用 `babel-jest` 處理 js  爲了能夠用es6語法
  '^.+\\.js$': '<rootDir>/node_modules/babel-jest',
  // 用 `vue-jest` 處理 `*.vue` 文件
  '.*\\.(vue)$': '<rootDir>/node_modules/vue-jest'
},複製代碼
testRegex:'(/__tests__/.*|(\\.|/)(test|spec))\\.[jt]sx?$' 
默認狀況下,Jest 將會遞歸的找到整個工程裏全部 .spec.js 或 .test.js 擴展名的文件 ,可根據須要修改複製代碼
  • 報錯集合
testURL: 'http://localhost',  不設置會報‘localstorage is not available for opaque origins’複製代碼
相關文章
相關標籤/搜索