I recently set up testing for my Vue project by following the instructions provided in this helpful guide here
Upon completion of the guide, I proceeded to create a test for one of my components. However, when I ran jest
, I encountered the following error:
unknown: Unexpected token (10:4)
8 | export default {
9 | computed: {
> 10 | ...mapGetters([
| ^
11 | 'user'
12 | ])
13 | }
Despite conducting research on this error and examining other sample projects, I have yet to determine how to resolve it.
Your assistance regarding this matter would be greatly appreciated.
App.vue
<template>
<div id="app" />
</template>
<script>
import { mapGetters } from 'vuex'
export default {
computed: {
...mapGetters([
'user'
])
}
}
</script>
App.spec.js
import { shallow } from '@vue/test-utils'
import App from './App'
describe('App', () => {
it('works', () => {
const wrapper = shallow(App)
expect(wrapper.isVueInstance()).toBeTruthy()
})
})
.babelrc
{
"presets": [
["env", { "modules": false }]
],
"env": {
"test": {
"presets": [
["env", { "targets": { "node": "current" }}]
]
}
}
}
package.json (just jest part)
"jest": {
"moduleFileExtensions": [
"js",
"json",
"vue"
],
"transform": {
".*\\.(vue)$": "<rootDir>/node_modules/vue-jest",
"^.+\\.js$": "<rootDir>/node_modules/babel-jest"
},
"snapshotSerializers": [
"<rootDir>/node_modules/jest-serializer-vue"
],
"moduleNameMapper": {
"^@/(.*)$": "<rootDir>/src/$1"
}
}