javascriptunit-testingvue.jsjestjspreset

Trying vue-test-utils-getting-started with default config and Preset Not Found when run


I am trying to do a unit test by following the official guide by cloning the demo repository vue-test-utils-getting-started.

Step to Reproduce

  1. npm install (only run once after cloning vue-test-utils-getting-started)
  2. Because the file is prepared, run npm test could see the following error
● Validation Error:

  Preset @vue/cli-plugin-unit-jest/presets/no-babel/jest-preset.js not found.

  Configuration Documentation:
  https://facebook.github.io/jest/docs/configuration.html

If cat the file

cat @vue/cli-plugin-unit-jest/presets/no-babel/jest-preset.js

it does display the content meaning that the file does exist in the path

If comment out the line, it works. It seems that the mechanism to load the preset file is buggy. Does any one know how to load the preset correctly?

// jest.config.js

module.exports = {
  // this is installed by default, but not working, many people encounters, "not found" but file exists 
  // preset: '@vue/cli-plugin-unit-jest/presets/no-babel'
}

Solution

  • I just found out the reason.

    It is because vue-test-utils-getting-started using an old version of jest which found preset path reading problem. So, updating all the packages to latest will resolve it.

    An addition note to the vue-test-utils-getting-started repository. The last update was 3 years ago. So, in case if anyone encounter similar matters. If using an old repository with node package dependency, the old versions defined inside could be the problem. Thanks anyway who pay a visit to this question. It is resolved.