Unit Testing Vue Component - Jest Setup - Unexpected Identifier error Unit Testing Vue Component - Jest Setup - Unexpected Identifier error vue.js vue.js

Unit Testing Vue Component - Jest Setup - Unexpected Identifier error


You are using ES6 features in your test, namely the import statement, so you need to compile them down to ES5 using a preset.

Create a babel.config.js and add @babel/preset-env, like so,

//babel.config.jsmodule.exports = {  presets: ["@babel/preset-env"]};

Next, in your package.json under the jest setting, let jest know where the root of your test code is located, and the module directories that will be recursively searched by jest, like so,

//package.json"roots": [  "test"],"moduleDirectories": [  "test",  "node_modules"],