[Vuejs]-Error running npm run unit in Vue.js (babel-preset-stage-2)

-1👍

After a few tries, I get it. It was really an error of configuration, I was missing some arguments. With theses changes in package.json everything works perfectly:

"jest": {
    "moduleFileExtensions": [
      "js",
      "jsx",
      "json",
      "vue"
    ],
    "transform": {
      "^.+\\.vue$": "vue-jest",
      ".+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$": "jest-transform-stub",
      "^.+\\.jsx?$": "babel-jest"
    },
    "transformIgnorePatterns": [
      "/node_modules/(?!jest-test)"
    ],
    "moduleNameMapper": {
      "^@/(.*)$": "<rootDir>/src/$1"
    },
    "snapshotSerializers": [
      "jest-serializer-vue"
    ],
    "testMatch": [
      "**/tests/unit/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)"
    ],
    "testURL": "http://localhost/",
    "watchPlugins": [
      "jest-watch-typeahead/filename",
      "jest-watch-typeahead/testname"
    ]
  }

If you’re not using Vue, and testing with pure javascript, these line works just fine:

"jest": {
    "moduleFileExtensions": [
      "js",
      "json"
    ],
    "transform": {
      ".+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$": "jest-transform-stub",
      "^.+\\.jsx?$": "babel-jest"
    },
    "transformIgnorePatterns": [
      "/node_modules/(?!jest-test)"
    ],
    "moduleNameMapper": {
      "^@/(.*)$": "<rootDir>/src/$1"
    },
    "testMatch": [
      "**/tests/**/*.test.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)"
    ],
    "testURL": "http://localhost/"
  }

If it still not working, tring configure Babel and run it with Webpack. I used this configuration in both cases and worked.

0👍

Have a look into vue-cli and see if the tests work on a new install, it looks like you have a Babel problem you are using old Babel ‘babel-core’. If you want a quick way to get Vue up and running try codesandbox.io.

Also you might want to edit you post as you have posted your email in the package.json file

0👍

Looks like you don’t have correctly installed babel. You must delete the node_modules folder and install the latest babel version runing npm install or yarn install. Then try to run npm run unit again. The best solution is using Vue CLI in this page you can find the vue babel configuration manual Vue Babel config. Babel plugin on github

Leave a comment