Several of my unit tests are failing to run with the following error:
Jest encountered an unexpected token
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
Here's what you can do:
• If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/en/ecmascript-modules for how to enable it.
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/en/configuration.html
Details:
SyntaxError: Unexpected token (9:80)
at Parser.pp$4.raise (node_modules/vue-template-es2015-compiler/buble.js:2757:13)
at Parser.pp.unexpected (node_modules/vue-template-es2015-compiler/buble.js:646:8)
at Parser.pp$3.parseExprAtom (node_modules/vue-template-es2015-compiler/buble.js:2196:10)
at Parser.<anonymous> (node_modules/vue-template-es2015-compiler/buble.js:6003:24)
...
My jest config is as follows:
{
moduleFileExtensions: [
'js',
'jsx',
'json',
// tell Jest to handle *.vue files
'vue',
],
transform: {
// process *.vue files with vue-jest
'^.+\\.vue$': require.resolve('vue-jest'),
'.+\\.(css|styl|less|sass|scss|png|jpg|svg|ttf|woff|woff2|PNG)$':
'jest-transform-stub',
'^.+\\.jsx?$': require.resolve('babel-jest'),
},
transformIgnorePatterns: ['node_modules/(?!bootstrap)'],
// support the same @ -> src alias mapping in source code
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
'\\.(css|sass)$': 'identity-obj-proxy',
},
testEnvironment: 'jest-environment-jsdom-fifteen',
// serializer for snapshots
snapshotSerializers: ['jest-serializer-vue'],
testMatch: [
'**/tests/unit/**/*.spec.[jt]s?(x)',
'**/__tests__/*.[jt]s?(x)',
],
// https://github.com/facebook/jest/issues/6766
testURL: 'http://localhost/',
watchPlugins: [
require.resolve('jest-watch-typeahead/filename'),
require.resolve('jest-watch-typeahead/testname'),
]
}
I'm at a loss for how to debug this error when it doesn't seem to specify the actual token that's unexpected (unless it's whitespace) and it doesn't seem to be pointing to any compon