'jest testing with babel undefined (reading 'getCacheKey')

FAIL tests/Unit/example.spec.js ● Test suite failed to run

TypeError: Cannot read properties of undefined (reading 'getCacheKey')

  at Object.getCacheKey (node_modules/vue3-jest/lib/index.js:13:19)

----------|----------|----------|----------|----------|-------------------| File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s | ----------|----------|----------|----------|----------|-------------------| All files | 0 | 0 | 0 | 0 | | ----------|----------|----------|----------|----------|-------------------| Test Suites: 1 failed, 1 total Tests: 0 total Snapshots: 0 total Time: 1.544s Ran all test suites.

package.json

  "devDependencies": {
    "@inertiajs/inertia": "^0.8.4",
    "@inertiajs/inertia-vue3": "^0.3.5",
    "@inertiajs/progress": "^0.2.4",
    "@tailwindcss/forms": "^0.2.1",
    "@tailwindcss/typography": "^0.3.0",
    "@vue/cli-plugin-unit-jest": "~4.5.0",
    "@vue/cli-service": "^4.5.15",
    "@vue/compiler-sfc": "^3.0.5",
    "@vue/test-utils": "^2.0.0-0",
    "axios": "^0.21.1",
    "babel-jest": "^22.4.3",
    "flush-promises": "^1.0.2",
    "jest": "^27.3.1",
    "laravel-mix": "^6.0.6",
    "lodash": "^4.17.19",
    "postcss": "^8.1.14",
    "postcss-import": "^12.0.1",
    "tailwindcss": "^2.0.1",
    "typescript": "~3.9.3",
    "vue": "^3.0.5",
    "vue-loader": "^16.1.2",
    "vue3-jest": "^27.0.0-alpha.1"
  }

jest.config.js

const config = {
  preset: '@vue/cli-plugin-unit-jest',
  collectCoverage: true,
  transform: {
    '^.+\\.vue$': 'vue3-jest',
    '^.+\\.tsx?$': 'ts-jest',
    '^.+\\.jsx?$': 'babel-jest'
  },
  testMatch:["**/tests/Unit/*.spec.[jt]s?(x)"],

  verbose: true,
};

any ideas? thanks



Solution 1:[1]

I was experiencing the same issue, for me updating babel-jest to the latest version (27.5.1) fixed the issue.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ben