question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Testing with Jest: SyntaxError: Unexpected identifier

See original GitHub issue

Hi 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:open
  • Created 4 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

7reactions
amitkumarcommented, Mar 13, 2020

For anyone using nuxt, I had the same error. Adding vue-agile to the transpile options in nuxt.config.js fixed it:

build: {
    transpile: [
      'vue-agile'
    ],
}

Thanks @JakeBeresford for clueing me in on the fix!

2reactions
JakeBeresfordcommented, Jan 20, 2020

I have found a solution to this problem. In your jest configuration you need to exclude vue-agile from the transformIgnorePatterns like this

transformIgnorePatterns: [ '/node_modules/(?!vue-agile)' ],

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found