Testing with Jest: SyntaxError: Unexpected identifier
See original GitHub issueHi guys,
I am trying to test a component which uses VueAgile locally register and I am getting the following error:
/Users/gustavobissolli/Code/chatfood-webview/node_modules/vue-agile/src/index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import VueAgile from './Agile'
^^^^^^^^
SyntaxError: Unexpected identifier
22 | <script>
23 | import LoyaltyProgram from "./LoyaltyProgram";
> 24 | import { VueAgile } from "vue-agile";
| ^
25 | import { isEmpty, isNil } from "ramda";
26 |
27 | export default {
at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:403:17)
at src/components/menu/carousel/Index.vue:24:1
at Object.<anonymous> (src/components/menu/carousel/Index.vue:73:3)
This is my component:
<template>
<div class="container-fluid p-0" v-if="isComponentVisible">
<Carousel
:autoplay="true"
:autoplaySpeed="5000"
:speed="500"
:navButtons="false"
:unagile="activeCarousel"
>
<LoyaltyProgram
v-if="hasLoyaltyProgram"
:rewardPoints="rewardPoints"
:loyaltyProgram="loyaltyProgram"
/>
<div class="px-3" v-if="note">
<div class="alert alert-success mb-0 px-3" v-html="note" />
</div>
</Carousel>
</div>
</template>
<script>
import LoyaltyProgram from "./LoyaltyProgram";
import { VueAgile } from "vue-agile";
import { isEmpty, isNil } from "ramda";
export default {
components: {
Carousel: VueAgile,
LoyaltyProgram
},
props: {
note: {
type: String,
default: () => null
},
rewardPoints: {
type: Number,
default: () => 0
},
loyaltyProgram: {
type: Object,
default: () => {}
}
},
computed: {
hasLoyaltyProgram() {
return !isEmpty(this.loyaltyProgram);
},
isComponentVisible() {
return this.hasLoyaltyProgram || !isNil(this.note);
},
activeCarousel() {
return !this.note || !this.hasLoyaltyProgram;
}
}
};
</script>
Any idea on how to fix it?
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Jest - SyntaxError: Unexpected identifier - Stack Overflow
Lately I find that I don't need babel-jest at all, and can get by simply with @babel/preset-env , and the following .babelrc :...
Read more >SyntaxError: Unexpected identifier #8660 - facebook/jest
Expected behavior. Two test case should be executed successfully. Link to repl or repo (highly encouraged). https://github.com/joe223/ ...
Read more >How I Fixed The Unexpected Token Error In Jest
The "issue" is that Jest only wants to process CommonJS-style code. So for the Jest tests to run, it first needs to be...
Read more >Jest: Unexpected token 'export' - Sendbird Community
When I run my tests using Jest, I got an SyntaxError: Unexpected token 'export' from node_modules/@sendbird/chat/sendbird.js:1.
Read more >jest encountered an unexpected token jest failed to parse a ...
Jest encountered an unexpected token Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For anyone using nuxt, I had the same error. Adding
vue-agile
to the transpile options in nuxt.config.js fixed it:Thanks @JakeBeresford for clueing me in on the fix!
I have found a solution to this problem. In your jest configuration you need to exclude vue-agile from the
transformIgnorePatterns
like thistransformIgnorePatterns: [ '/node_modules/(?!vue-agile)' ],