I am currently utilizing vue.js and attempting to incorporate async/await in jest (with vue utils test).
it('async/await test', async () => {
await wrapper.setData({
foo: 'bar',
});
// ...
});
Although I can use the import statement, an error occurs when running the 'yarn test' (jest) command, even though I did not export anything from the test file.
Details:
export default function _asyncToGenerator(fn) {
^^^^^^
SyntaxError: Unexpected token 'export'
at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1517:14)
at Object.<anonymous> (__test__/TestComponent.test.js:9:49)
Here are my configuration files:
// jest.config.json
{
"verbose": true,
"testEnvironment": "node",
"moduleFileExtensions": ["js", "vue"],
"moduleNameMapper": {
"^@/(.*)$": "<rootDir>/resources/assets/js/components/$1"
},
"transform": {
"^.+\.js$": "<rootDir>/node_modules/babel-jest",
".*\.(vue)$": "<rootDir>/node_modules/vue-jest"
},
"snapshotSerializers": ["<rootDir>/node_modules/jest-serializer-vue"]
}
// babel.config.jss
module.exports = {
presets: [
'@vue/app',
['@babel/preset-env', { targets: { node: 'current' } }],
],
plugins: [
'@babel/plugin-proposal-nullish-coalescing-operator',
'@babel/plugin-proposal-optional-chaining',
'@babel/plugin-proposal-logical-assignment-operators',
'@babel/plugin-proposal-numeric-separator',
],
};
environment
System:
OS: Windows 10 10.0.19043
CPU: (8) x64 Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
Binaries:
Node: 14.15.4 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.10 - C:\Program Files\nodejs\yarn.CMD
npm: 6.14.10 - C:\Program Files\nodejs\npm.CMD
npmPackages:
jest: ^27.0.6 => 27.1.0
+
"@vue/test-utils": "^1.2.2"
"@babel/core": "^7.15.0"
"vue": "^2.6.10"
How can I resolve this issue? Below is a link to my sample test file code: https://gist.github.com/charmjeh/544455d49ff184750f17df8bb460b876