No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    @quasar/extras/mdi-v4 jest unit testing failing

    Help
    2
    2
    189
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Y
      ymzhang23 last edited by

      I am using the new SVG images. I have created a test for a header that contains a logo, name mdiMenu.

      import { mdiMenu } from '@quasar/extras/mdi-v4'
      

      But everything I am running the test: I always get this error:

      SyntaxError: Unexpected token 'export'
      
            29 | 
            30 | <script>
          > 31 | import { mdiMenu } from '@quasar/extras/mdi-v4'
      

      Do somebody else have encounter this problem and how can I solve this?

      This is the rest of the error message:

      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:
           • 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:
      
          C:\Users\YohnCheung\work\bitBucket\central-station\node_modules\@quasar\extras\mdi-v4\index.js:3
          export const mdiAbTesting = 'M4 2A2 2 0 0 0 2 4V12H4V8H6V12H8V4A2 2 0 0 0 6 2H4M4 4H6V6H4M22 15.5V14A2 2 0 0 0 20 12H16V22H20A2 2 0 0 0 22 20V18.5A1.54 1.54 0 0 0 20.5 17A1.54 1.54 0 0 0 22 15.5M20 20H18V18H20V20M20 16H18V14H20M5.79 21.61L4.21 20.39L18.21 2.39L19.79 3.61Z'
          ^^^^^^
      
          SyntaxError: Unexpected token 'export'
      
            29 | 
            30 | <script>
          > 31 | import { mdiMenu } from '@quasar/extras/mdi-v4'
               | ^
            32 | 
            33 | export default {
            34 |   name: 'Header',
      
            at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:537:17)
            at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:579:25)
            at src/components/header.vue:31:1
            at Object.<anonymous> (src/components/header.vue:73:3)
      
      1 Reply Last reply Reply Quote 1
      • luckylooke
        luckylooke last edited by

        Hello! 🙂
        Correct transformation need to be configured.

         ...
         transform: {
            '^.+\\.jsx?$': require.resolve('babel-jest'),
         },
         ...
        

        and ensure it is transformed

          transformIgnorePatterns: ['node_modules/(?!(quasar|quasar/*|@quasar|@quasar/*))'],
        

        more info here: https://stackoverflow.com/questions/63481304/quasar-extras-mdi-v4-jest-unit-testing-failing-on-unexpected-token-export
        please upvote if it helped you, thanks 🙏

        1 Reply Last reply Reply Quote 0
        • First post
          Last post